此表单包含许多其他输入正常工作,如<input>, <select> (not multiple) etc...
当我使用<select multiple
时,我无法确定问题的确切位置。我有以下代码:
<form action="phpaction.php" method="post">
<select name="states[]" multiple>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
...
</select>
// phpaction.php file
$statesArray=$_POST['states'];
print_r ($statesArray);
为什么不工作?我收到以下错误:Undefined index: states in phpaction.php on line 72
答案 0 :(得分:3)
试试这个:
<?php
if ($_SERVER['REQUEST_METHOD']==='POST') {
$statesArray=$_POST['states'];
print_r($statesArray);
}
?>
<form action="" method="post">
<select name="states[]" multiple>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
</select>
<input type="submit">
</form>