我有一个PHP自我验证表单,它验证所有字段但不报告要输出的复选框。我似乎无法找到一个澄清的例子。请帮忙!
//make sure one of the services requested checkboxes are checked
$require_one_of = array('walkSale','RawSale','groomSale'); //names of posted checkboxes
$one_set=false;
foreach($require_one_of as $key){
if(isset($_POST[$key])){
$one_set=true;
break;
}
}
if(!$one_set){
//error handling
$reasonErr= "You forgot to select a Service!";
}
HTML表单
<fieldset id="field3">
<legend id="legend3">Services Required:</legend>
<hr />
<input type="checkbox" name="walkSale" value="walkSale"
<?php if(isset($_POST['walkSale'])) echo "checked='checked'";?> class="textfield"/>I'm looking for a Dog Walker!
<input type="checkbox" name="RawSale" value="RawSale"
<?php if(isset($_POST['RawSale'])) echo "checked='checked'";?> class="textfield"/>I'm looking to purchase Raw Food!
<input type="checkbox" name="groomSale" value="groomSale"
<?php if(isset($_POST['groomSale'])) echo "checked='checked'";?> class="textfield"/>I'm looking for a Dog Groomer!
<span class="error">* <?php echo $reasonErr;?></span>
</fieldset>