開発環境
- OS X Lion - Apple(OS)
- Apache (Web Server)
- PHP (サーバーサイドプログラミング言語)
- TextWrangler(Text Editor) (BBEditの無料機能制限版、light版)
『初めてのPHP5』 (David Sklar 著、 桑村 潤 翻訳、 廣川 類 翻訳、 オライリー・ジャパン、2005年、ISBN978-4-87311-257-2)の6章(Webフォームの作成)6.7(演習問題)5を解いてみる。
5.
HTML、PHPのコード(TextWrangler)
<?php function p($name, $array){ foreach($array as $key => $value){ if(is_array($value)){ p($name . "[" . $key . "]", $value); } else { print "{$name}[{$key}] = {$value}<br />"; } } } function process_form(){ if($_POST){ p('$_POST', $_POST); } else { print <<<_HTML_ <form method="POST" action="$_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" value="0" name="sweetq"> <br /> <input type="submit" name="submit" value="order"> </form> _HTML_; } } process_form(); ?>
HTMLソース
<form method="POST" action="/~kamimura/kamimura_blog/learning_php/sample55.php"> 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" value="0" name="sweetq"> <br /> <input type="submit" name="submit" value="order"> </form>
0 コメント:
コメントを投稿