selectに値を入れる。
ご質問があったので書きます。こんな感じになります。ユーザの言語を選択するというものです。POST値はisoの2文字のコードを返します。
テンプレート form1.html
<html> <head> <title>Test for select box</title> </head> <body> <h1>Test for select box</h1> <form name='userlang' action='editlang.php' method='post'> <select name="lang"> <option var="{lang}" value="{iso}" selected="{selected}"> <span var="{name}">language</span> </option> </select> </form> </body> </html>
PHPコード
require_once '../phpoot.php'; $tmpl = new phpoot; //$tmpl->setErrorHandling(PEAR_ERROR_PRINT); $tmpl->setTemplateFile('./form1.html'); $model_data = array( 'lang' => array( array( 'name' => 'english', 'iso' => 'en' ), array( 'name' => 'japanese', 'iso' => 'ja', 'selected' => true ), array( 'name' => 'french', 'iso' => 'fr' ) ) ); $tmpl->display($model_data);
出力
<html> <head> <title>Test for select box</title> </head> <body> <h1>Test for select box</h1> <form name="userlang" action="editlang.php" method="post"> <select name="lang"> <option value="en"> english </option> <option value="ja" selected="selected"> japanese </option> <option value="fr"> french </option> </select> </form> </body> </html>
var="{lang}"の位置が少し重要。また、selected="{selected}"をデータをboolにすることで、有無を制御できます。