Php 如何在提交前检查复选框数组的内容
我有一个像这样的php函数Php 如何在提交前检查复选框数组的内容,php,javascript,arrays,forms,checkbox,Php,Javascript,Arrays,Forms,Checkbox,我有一个像这样的php函数 function printSelectedMembers($id) { $full_name = $this->getUserName($id); echo '<dl>'; echo '<dt><label for="event_show">Selected member :</label></dt>'; echo '<input type="checkbox"
function printSelectedMembers($id) {
$full_name = $this->getUserName($id);
echo '<dl>';
echo '<dt><label for="event_show">Selected member :</label></dt>';
echo '<input type="checkbox" name="pvtContacts[]" checked="checked" value="'.$id.'"/>'.$full_name;
echo '</dl>';
}
函数printedselectedmembers($id){
$full_name=$this->getUserName($id);
回声';
回显“选定成员:”;
回显“”。$全名;
回声';
}
在本例中,如果成员已在复选框数组(pvtContacts[])中,我希望删除该条目。在提交表单之前如何检查数组的内容?在注释中,您不能使用php检查字段,因为它们在表单提交后会被检查,但您可以使用javascript检查复选框是否被选中
<script type="text/javascript">
function checkForm(form) {
for (i=0; i<form.elements['pvtContacts[]'].length; i++) {
// this is where you start the checks or altering the form
// remove (but you have to setup an unique id for each field):
// var thisId = document.getElementById(form.elements['pvtContacts[]'][i].id);
// thisId.parentNode.removeChild(thisId);
if (form.elements['pvtContacts[]'][i].checked != true) {
// no all checkboxes are checked
return false;
}
}
return true;
}
</script>
函数检查窗体(窗体){
对于(i=0;iPhp无法在提交之前检查提交值。您需要使用客户端javascript。您的问题还不清楚。为什么不在创建html代码之前测试成员是否在数组中?提交是指将html发送给客户端还是指客户端提交表单(即按下提交按钮)?@Martin如果一个成员仍然在数组中,我想删除该成员。实际上,这是一个AJAX响应表单,用户可以在提交表单之前选择所选成员。因此,如果他错误地选择了一个用户,他必须能够删除他。但在我的情况下,该成员再次被选中!我使用的是onchange()事件