• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.