-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>

2 番目の方法:-

<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 に答える