<form name="search" method="post" >
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="category1">category1</option>
<Option VALUE="category2">category2</option>
</Select>
<input type="submit" name="search" value="Search" />
</form>
<?php
if(!empty($_POST)){
$options = array('category1'=> array('1' => 'dog', '2' => 'cat'), 'category2' =>array('1'=>'flower', '2'=>'grass'));
$input = trim($_POST['find']);
$category = $_POST['field'];
$output = $options[$category][$input];
echo $output;
}
?>
问题:
如果我输入1并选择'category2',它显示:flower,但输入字段变空,选择框回到'category1',有没有办法让输入框和选择框保留我输入的值就我而言,在我点击提交按钮后,“1”仍然在输入字段中,“category2”显示在选择框中。