我从 PHP 和 HTML 开始,想用三个下拉列表(选择标签)执行简单的代码。但是当我从一个中进行选择时,其他两个选定的值就会消失。我应该在提交时保存值然后回显吗?如果是,我该怎么做。示例代码将不胜感激。
<?php // formtest_2.php
$name_vid = $name_type = $name_model = "";
if (isset($_POST['vid']))$name_vid=($_POST['vid']);
else $name_vid="no";
if (isset($_POST['type']))$name_type=sanitizeString($_POST['type']);
else $name_type="no";
if (isset($_POST['model']))$name_model=sanitizeString($_POST['model']);
else $name_model="no";
echo <<<_END
<html>
<head>
<title>Form Test Two</title>
</head>
<body>
Make your selection:
<form action="formtest_2.php" method="post">
<select name="vid" size="1">
<option value="" selected>Product</option>
<option value = "apple">apple</option>
<option value = "cherry">cherry</option>
<option value = "orange">orange</option>
</select>
<input type="submit"/><br />
<select name="type" size="1">
<option value="" selected>Color</option>
<option value = "green">green</option>
<option value = "red">red</option>
<option value = "orange">orange</option>
</select>
<input type="submit"/><br />
<select name="model" size="1">
<option value="" selected>Model</option>
<option value = "1-a">1-a</option>
<option value = "2-b">2-b</option>
<option value = "3-c">3-c</option>
</select>
<input type="submit"/><br />
</form>
</body>
</html>
_END;
echo "Your selection is: $name_vid and $name_type and $name_model";
function sanitizeString($var)
{
$var = stripslashes($var);
$var = htmlentities($var);
$var = strip_tags($var);
return $var;
}
?>