Keep radio button selected after a form submit

馋奶兔 提交于 2019-12-22 08:03:22

问题


I am using below code to keep the radio button selection after a form submission, but it keep resetting to the last button after form submission

<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

How can I keep the selection ?


回答1:


isset() returns a boolean. As such, comparing directly to Yes/No is not what you want.

What you want is:

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


来源:https://stackoverflow.com/questions/18450998/keep-radio-button-selected-after-a-form-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!