【问题标题】:form check box value retain if form having 1 or more error如果表单有 1 个或多个错误,则表单复选框值保留
【发布时间】:2013-06-29 13:04:48
【问题描述】:

$facility=$_POST['interests'];

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

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

【问题讨论】:

  • 很抱歉我在解决这个问题时很沮丧,但在原始脚本中是正确的

标签: php forms


【解决方案1】:

我终于修复了这个错误

 <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'";
      }
?>

【讨论】:

  • 您应该说明问题所在
猜你喜欢
  • 1970-01-01
  • 2020-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多