-4

$facility=$_POST['兴趣'];

<input type="checkbox" name="interests[]" id="" value="wifi" value="<?php echo in_array('wifi', $facility)??>checked='checked'<?php:;?>" /><label class="check_label">Wifi</label>
<input type="checkbox" name="interests[]" id="" value="spa"  value="<?php echo in_array('spa', $facility)?>checked='checked'<?php:;?>"/><label class="check_label">Spa</label>

<input type="checkbox" name="interests[]" id="" value="pet allowed" value="<?php echo in_array('pet allowed', $facility)?>checked='checked'<?php:;?>"/><label class="check_label">Pet Allowed</label>

第二种方法:-

<input type="checkbox" name="interests[]" id="" value="wifi" value="<?php  in_array('wifi', $facility){?>checked='checked'<?php}?>" /><label class="check_label">Wifi</label>
<input type="checkbox" name="interests[]" id="" value="spa"  value="<?php  in_array('spa', $facility){?>checked='checked'<?php}?>"/><label class="check_label">Spa</label>
<input type="checkbox" name="interests[]" id="" value="pet allowed" value="<?php  in_array('pet allowed', $facility){?>checked='checked'<?php}?>"/><label class="check_label">Pet Allowed</label>

如果用户犯了任何错误,我会应用这两种方法以保留表单中的帖子值。如果他犯了错误复选框在提交后仍然检查,但它不起作用。

4

1 回答 1

0

最后我修复了这个错误

 <input type="checkbox" name="interests[]" id="" value="wifi" <?php if(in_array('wifi', $facility)==TRUE){echo "value=wifi checked='checked'";}?> /><label class="check_label">Wifi</label>
                    <input type="checkbox" name="interests[]" id="" value="spa"  <?php if(in_array('wifi', $facility)==TRUE){echo "value=spa checked='checked'";}?>/><label class="check_label">Spa</label>
                    <input type="checkbox" name="interests[]" id="" value="pet allowed" <?php if(in_array('wifi', $facility)==TRUE){echo "value=pet allowed checked='checked'";}?>/><label class="check_label">Pet Allowed</label>

以前我使用的脚本逻辑不正确:-

<?php  
  in_array('wifi', $facility){
?> checked='checked'
<?php}?>" //there is no if else exist how it check condition is true or false

现在我更改该脚本并使用条件:-

<?php 
      if(in_array('wifi', $facility)==TRUE){
         echo "value=wifi checked='checked'";
      }
?>
于 2013-07-01T07:04:04.957 回答