2012年11月6日火曜日

開発環境

『初めてのPHP5』 (David Sklar 著、 桑村 潤 翻訳、 廣川 類 翻訳、 オライリー・ジャパン、2005年、ISBN978-4-87311-257-2)の6章(Webフォームの作成)6.7(演習問題)1を解いてみる。

1.

次のような配列になる。

$_POST = array(
  'noodle' => "barbecued pork",
  "sweet" => array("puff","ricemeat"),
  "sweet_q" => "4",
  "submit" => "order");

var_dump()で出力して確認。

HTML、PHPのコード(TextWrangler)

sample52.php

<form method="POST" action="<?php $_SERVER['PHP_SELF'] ?>">
Braised Noodles with: 
<select name="noodle">
  <option>crab meat</option>
  <option>mushroom</option>
  <option>barbecued pork</option>
  <option>shredded ginger and green onion</option>
</select>
<br />
Sweet:
<select name="sweet[]" multiple>
<option value="puff"> Sesame Seed Puff
<option value="square"> Coconut Milk Gelatin Square
<option value="cake"> Brown Sugar Cake
<option value="ricemeat"> Sweet Rice and Meat
</select>
<br />
Sweet Quantity: <input type="text" name="sweetq">
<br />
<input type="submit" name="submit" value="order">
</form>
<?php
  var_dump($_POST);
?>

HTMLソース(送信後)

<form method="POST" action="">
Braised Noodles with: 
<select name="noodle">
  <option>crab meat</option>
  <option>mushroom</option>
  <option>barbecued pork</option>
  <option>shredded ginger and green onion</option>
</select>
<br />
Sweet:
<select name="sweet[]" multiple>
<option value="puff"> Sesame Seed Puff
<option value="square"> Coconut Milk Gelatin Square
<option value="cake"> Brown Sugar Cake
<option value="ricemeat"> Sweet Rice and Meat
</select>
<br />
Sweet Quantity: <input type="text" name="sweetq">
<br />
<input type="submit" name="submit" value="order">
</form>
array(4) {
  ["noodle"]=>
  string(14) "barbecued pork"
  ["sweet"]=>
  array(2) {
    [0]=>
    string(4) "puff"
    [1]=>
    string(8) "ricemeat"
  }
  ["sweetq"]=>
  string(1) "4"
  ["submit"]=>
  string(5) "order"
}

0 コメント:

コメントを投稿