開発環境
- 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(演習問題)2を解いてみる。
2.
HTML、PHPのコード(TextWrangler)
<?php function process_form(){ if($_POST){ foreach($_POST as $key => $value){ print "$key: $value<br />"; } } 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" name="sweetq"> <br /> <input type="submit" name="submit" value="order"> </form> _HTML_; } } process_form(); ?>
HTMLソース
送信前
<form method="POST" action="/~kamimura/kamimura_blog/learning_php/sample53.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" name="sweetq"> <br /> <input type="submit" name="submit" value="order"> </form>
送信後
noodle: mushroom<br />sweet: Array<br />sweetq: 10<br />submit: order<br />
0 コメント:
コメントを投稿