Welcome Guest, Not a member yet? Register   Sign In
Setting a default value for a radio button with set_radio helper function
#1

[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?
#2

[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.




Theme © iAndrew 2016 - Forum software by © MyBB