我在这里四处寻找了一些示例,但它们中的许多对于我掌握的PHP来说要么太高级,要么它们的示例对于它们自己的项目太具体了。我目前正在为PHP表单的一个非常基本的部分而努力。
我正在尝试创建一个带有几个复选框的表单,每个复选框分配一个不同的值,我希望将这些复选框发送到一个变量(array?)我可以稍后回显/使用,在我的情况下,我将在电子邮件中发送检查的值。
到目前为止,我已经尝试了一些变体,但最接近它的是...
<form method='post' id='userform' action='thisform.php'>
<tr>
<td>Trouble Type</td>
<td>
<input type='checkbox' name='checkboxvar' value='Option One'>1<br>
<input type='checkbox' name='checkboxvar' value='Option Two'>2<br>
<input type='checkbox' name='checkboxvar' value='Option Three'>3
</td>
</tr>
</table>
<input type='submit' class='buttons'>
</form>
<?php
$checkboxvar[] = $_REQUEST['checkboxvar'];
?>在那里我会在我的电子邮件中回显$checkboxvar[]。我是不是完全错了?我的另一个想法是使用大量的if语句。
发布于 2012-12-25 07:09:13
您需要使用方括号表示法才能将值作为数组发送:
<form method='post' id='userform' action='thisform.php'>
<tr>
<td>Trouble Type</td>
<td>
<input type='checkbox' name='checkboxvar[]' value='Option One'>1<br>
<input type='checkbox' name='checkboxvar[]' value='Option Two'>2<br>
<input type='checkbox' name='checkboxvar[]' value='Option Three'>3
</td>
</tr>
</table>
<input type='submit' class='buttons'>
</form>但请注意,只有选中的复选框的值才会被发送。
https://stackoverflow.com/questions/14026361
复制相似问题