• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
form_validation return after first field error ?

Hi, so recently i started to use CI, and im at a point where i need to validate my forms and i have a question

Is there a good reason for this code ?
if ( ! isset($this->_error_array[$row['field']]))
    $this->_error_array[$row['field']] = $message;


(Line 814 @ system/form_validation).

I don't want to piss off visitors with just one error of specific field at a time, i want to show then all.

Quote:I want to get this:
 array(2) {
   string(72) "The xxx field must be at least 3 characters in length."
   string(72) "The xxx field does not match the yyy field."

Not this:
 array(1) {
   string(72) "The xxx field must be at least 3 characters in length."

So from the code above i'm now using only this
$this->_error_array[$row['field']][] = $message;

i don't like to mess with core code, so is this the right approach ? maybe im missing something ?

sorry for English Smile


Are you using the builtin CI form validation ( https://codeigniter.com/user_guide/libra...tion-rules )?

@php_rocs, yes

If your question is actually whether you can get all errors instead of just the first one, then yes ... https://www.codeigniter.com/user_guide/l...rror_array

Treat that as an array, and iterate over it, building your responses or view parameters ... possible.
Or, the user guide (same page) shows splitting them off individually, to show specific error message beside each field (more work).

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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