views:

69

answers:

2

On a text input, this is how you would "remember" the value the user entered if the form gets submitted to itself, for say a picture upload tool which requires that, so the user wont have to type everything into the form again after uploading a picture.

   <input type="text" id="text" name="text" value="<?php echo @$_POST['text'];?>">

but how is this done when it comes to radios?

I would prefer not to create the actual radio with php, I would prefer another solution. But in the end I would go with the easiest! Javascript is also okay to use here!

Thanks

+3  A: 
<input type="radio" id="radio_button_1" name="radio_button" value="1"<?php if($_POST['radio_button'] == 1) { print ' checked="checked"'; } ?> />
<input type="radio" id="radio_button_2" name="radio_button" value="2"<?php if($_POST['radio_button'] == 2) { print ' checked="checked"'; } ?> />
ceejayoz
Yep, you're right. missed the ""'s, You beat me to it anyway, +1
munch
A: 

To short further, you can write this statement as:

<input type="radio" id="radio_button_2" name="radio_button" value="2" <?=isset($_POST['radio_button']) ? "checked":"" ?> />
Adeel