Welcome Guest, Not a member yet? Register   Sign In
Question about form validation
#2

[eluser]Twisted1919[/eluser]
If you know for sure your number of checkboxes, do a for() loop, no problem with this.
But i would use arrays so instead of <input name="a1" /><input name="a2" /> i would use
<input name="a[]" />, then i wouldn't validate this array at all in the form_validation rules, instead, i would do it after the validation has passed, something like:
Code:
if($this->form_validation->run())
{
   if(isset($_POST['a'])&&is;_array($_POST['a']))
   {
      $a=$_POST['a'];
      $a=$this->security->xss_clean($a);
      foreach($a AS $key=>$value)
      {
          if(empty($value)||strlen($value)>255)
          {
             //trigger error.
          }
      }
   }
   else
   {
     //trigger error: come one, check something...
   }
}


Messages In This Thread
Question about form validation - by El Forum - 06-06-2011, 08:06 AM
Question about form validation - by El Forum - 06-06-2011, 08:25 AM
Question about form validation - by El Forum - 06-06-2011, 11:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB