【问题标题】:Keep radio button selected after a form submit提交表单后保持单选按钮处于选中状态
【发布时间】:2013-08-29 08:21:38
【问题描述】:

我使用下面的代码在表单提交后保持单选按钮选择,但在表单提交后它一直重置到最后一个按钮

<input type="radio" name="button" value="Yes" <?php if(isset($_POST['button']) == 'Yes')  echo ' checked="checked"';?> />Yes
<input type="radio" name="button" value="No" <?php if(isset($_POST['button']) == 'No')  echo ' checked="checked"';?> />No

如何保留选择?

【问题讨论】:

    标签: php forms radio-button


    【解决方案1】:

    isset() 返回一个boolean。因此,直接与Yes/No 比较不是您想要的。

    你想要的是:

    if (isset($_POST['button']) && $_POST['button'] == 'Yes')
    

    【讨论】:

      猜你喜欢
      • 2013-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-13
      • 2017-11-05
      • 1970-01-01
      相关资源
      最近更新 更多