開発環境
- OS X Lion - Apple(OS)
- Apache (Web Server)
- PHP (サーバーサイドプログラミング言語、スクリプト言語)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
『初めてのPHP5』 (David Sklar 著、 桑村 潤 翻訳、 廣川 類 翻訳、 オライリー・ジャパン、2005年、ISBN978-4-87311-257-2)の6章(Webフォームの作成)6.7(演習問題)5を解いてみる。
5.
HTML、PHPのソースコード(BBEdit)
<?php
if(! $_POST){
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="sweet_q">
<br />
<input type="submit" name="submit" value="Order">
</form>
_HTML_;
} else {
process_form();
}
// 問題の関数
function print_array($a, $pre){
foreach($a as $key => $value){
if(is_array($value)){
print_array($value, $pre . "['" . $key . "']");
} else {
print $pre . "['" . htmlentities($key) . "'] = " . htmlentities($value) . "<br />";
}
}
}
function process_form(){
print_array($_POST, "$_POST");
}
?>
0 コメント:
コメントを投稿