• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
form validation errors

#1
Hello.If the field has a few rules such as 'required|numeric|max_length[11]' why the errors are displayed one at a time instead of all at once?Is there a solution to this problem?
Reply

#2
There are two types of methods for showing form errors:

PHP Code:
<?php echo validation_errors(); ?> // shows all form errors

<form_open>

    <?php echo form_error('username'); ?> // only shows this error
    
</form> 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
Thumbs Down 
I am not sure it is a problem. The error that is displayed is the first error that fails for a form field. Testing every rule and reporting on them all would lead to some really long form field error messages and lots of repeated or useless information.

Take for example

PHP Code:
$this->form_validation->set_rules('name''NAME''trim|required|min_length[10]|max_length[50]|alpha_numeric_spaces'); 

This might produce, when left blank, an error like:

Quote:The NAME field is required. The Name field must contain a minimum of 10 characters. The Name field must contain only alpha numeric characters or spaces.

Which in my opinion is too much information. Much better to simply say that the field is required.

Personally on my forms I like to indicate (in small help text) the expected submission. So in this case I would have something like:

Quote:e.g. John Jones [required, 10-50 chars, alpha numeric & spaces]

I then replace that help text with the error message if an error exists, with error delimiters making the text red, something like:

PHP Code:
<class="help-text"><?php echo (form_error('name') != '' form_error('name') : 'e.g. John Jones [required, 10-50 chars, alpha numeric & spaces]'); ?></p> 

Also in bootstrap you can easily mark the field input in red with the 'has-error' class:

PHP Code:
<div class="form-group <?php echo (form_error('name') != '' ? 'has-error' : ''); ?>"

Which has nothing to do with your question but I thought I would mention it anyway :-)
Reply

#4
(06-29-2016, 02:08 PM)InsiteFX Wrote: There are two types of methods for showing form errors:

PHP Code:
<?php echo validation_errors(); ?> // shows all form errors

<form_open>

    <?php echo form_error('username'); ?> // only shows this error
    
</form> 

$this->form_validation->set_rules('name', 'name', 'trim|min_length[3]|numeric');

if( ! $this->form_validation->run()){
   echo validation_errors();
}


If the value of the field "name" will be "some text" I need you deduced error "min_length" and "numeric" and not just a mistake, "min_length".Thank you!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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