Welcome Guest, Not a member yet? Register   Sign In
Cannot get form validation > set_radio to work
#1

[eluser]Jakobud[/eluser]
I copy/pasted the code from the User Guide into my form:

Code:
<input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', TRUE); ?> />
<input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2'); ?> />

First of all, when I load the page initially, neither radio button is checked. Isn't the 3rd argument of set_radio supposed to set the default value? Cause it doesn't seem to work.

Next, after submitting my form and seeing the validation fail, the page loads back up again, and again, neither radio button is checked, even if I check one of them before submitting.

What am I doing wrong here?
#2

[eluser]Jakobud[/eluser]
Bump. Any ideas here? I really don't want to resort to using Javascript to validate my form, but I may have to if this doesn't work.
#3

[eluser]cideveloper[/eluser]
One thing you need to make sure you do is validate the radio field in the controller. This is part of the design of codeigniter. Even if you just use trim in the set_rules for the specific field. If you post the specific sections of your views and controller more help can be given.

View

Code:
<p>
<label for="like_site">Do you like this site?</label><br />
&lt;input type="radio" name="like_site" value="yes" &lt;?php echo set_radio('like_site', 'yes', TRUE); ?&gt; /&gt;
&lt;input type="radio" name="like_site" value="no" &lt;?php echo set_radio('like_site', 'no'); ?&gt; /&gt;
<span id="like_site_error">&lt;?php echo form_error('like_site'); ?&gt;</span>
</p>

Controller

Code:
$this->form_validation->set_rules('like_site', 'Like/Dislike', 'trim');




Theme © iAndrew 2016 - Forum software by © MyBB