PHP使用方括号语法将表单输入转换为数组,因此使用name="education[]"
时将获得一个数组:
$educationValues = $_POST['education']; // Returns an array
print_r($educationValues); // Shows you all the values in the array
因此,例如:
<p><label>Please enter your most recent education<br>
<input type="text" name="education[]">
</p>
<p><label>Please enter any prevIoUs education<br>
<input type="text" name="education[]">
</p>
<p><label>Please enter any prevIoUs education<br>
<input type="text" name="education[]">
</p>
将为您提供$_POST['education']
数组内所有输入的值。
在JavaScript中,通过id获取元素更有效。
document.getElementById("education1");
ID不必与名称匹配:
<p><label>Please enter your most recent education<br>
<input type="text" name="education[]" id="education1">
</p>