5

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 ?

4

1 回答 1

12

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

你想要的是:

if (isset($_POST['button']) && $_POST['button'] == 'Yes')
于 2013-08-26T18:55:35.603 回答