CodeIgniter Forums
Setting a default value for a radio button with set_radio helper function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Setting a default value for a radio button with set_radio helper function (/showthread.php?tid=23250)



Setting a default value for a radio button with set_radio helper function - El Forum - 10-05-2009

[eluser]HobbesTheTiger[/eluser]
Hi all,
I'm using the [/code]set_radio helper function to re-populate a radio button.
I know from documentation that it's possible to use the same function to set an item as the default, but I can't get it to work.

Below there's my code.
In the controller I have:

Code:
$this->form_validation->set_rules('patient_sex','Sex','required');

And in the view:
Code:
<div>
    <label for="patient_sex">Sex</label>
    &lt;input type="radio" name="patient_sex" value="male" &lt;?= set_radio('patient_sex', 'male', TRUE); ?&gt; /&gt;Male
    &lt;input type="radio" name="patient_sex" value="female"  &lt;?= set_radio('patient_sex', 'female'); ?&gt;  /&gt;Female
    &lt;?= form_error('patient_sex') ?&gt;
</div>

When I load the form for the first time, no item is selected.
Perhaps I've missed something?


Setting a default value for a radio button with set_radio helper function - El Forum - 10-06-2009

[eluser]HobbesTheTiger[/eluser]
Sorry, this is definitely NOT a bug. The function failed to re-populate the radio button because the code around the code I posted above contained, by mistake, another input element with the same name.