Welcome Guest, Not a member yet? Register   Sign In
form validation and checking for allowed values for example in listbox
#4

[eluser]CroNiX[/eluser]
You can set the error message, and retrieve it. See the "callbacks" section of the form validation library in the user guide.
Code:
function valid_array_element($str, $allowed)
{
  $allowed = explode(';', $allowed);
  if (in_array($str, $allowed))
  {
    return TRUE;  //return TRUE, passed the rule
  }
  else
  {
    //failed rule, set error message and return FALSE
    $this->form_validation->set_error('valid_array_element', 'The %s field can only be one of the following options: ' . implode(', ', $allowed));
    return FALSE;  
  }
}

Then in your form, where this form element is, you'd show the individual error like any other validation error.
Code:
echo form_error('name-of-field-this-rule-was-applied-on');
Which would show "The Somefield field can only be one of the following options: a, aa, aaa", if it failed.


Messages In This Thread
form validation and checking for allowed values for example in listbox - by El Forum - 12-01-2012, 03:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB