Welcome Guest, Not a member yet? Register   Sign In
Validation and Select Item? [solved]
#1

[eluser]Glowball[/eluser]
I'm successfully using the validation class with text and textarea fields, but I can't get it to validate a <select> field. How do I do this? In this example, the menu is of all of the states and the values are all two-digit codes. I want to make it required and two digits only.

Controller Snippet
Code:
$rules['state_abbr'] = "exact_length[2]";
$this->validation->set_rules($rules);

View Snippet
Code:
<select name="state_abbr" size="1">
<option value="">Select a State</option>
&lt;?php while (list($state_abbr, $state) = each($states)):?&gt;
<option value="&lt;?=$state_abbr;?&gt;" &lt;?=$this->validation->set_select('state_abbr', $state_abbr);?&gt; >&lt;?=$state;?&gt;</option>            
&lt;?php endwhile;?&gt;
</select>

It's in a form with other text fields and they are getting validated. This one select field is getting skipped. What's the trick? Thanks!
#2

[eluser]Glowball[/eluser]
I have no idea why, but I added a callback function to it (after the character check) and now it works. I was trying to start simple and that's when it wasn't working. I have no idea why it works, but it does now. Go figure!




Theme © iAndrew 2016 - Forum software by © MyBB