CodeIgniter Forums
concat validation rules with form_validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: concat validation rules with form_validation (/showthread.php?tid=67982)



concat validation rules with form_validation - annx10 - 05-04-2017

Hi.

I have a doubt about validaton files with form_validation library when concat several rules with pipes(|).

For example. I have an email field that I validate with: required|max_length[15]|valid_email.
Then, if user puts a text with more than 15 characters and in addition isn't valid email, my application only shows error by max_length exceed but like I am using validations_errors() I think that it must show both errors, not?

Is this correct?
For additional info I am using MY_Form_validation extending Form_validation with some custom rules, that I don't know if affects.

Thanks.


RE: concat validation rules with form_validation - Martin7483 - 05-04-2017

This behaviour is normal. Validation runs one rule per field at a time.
But why would you want to restrict an email field to a max length of 15?


RE: concat validation rules with form_validation - marksman - 05-04-2017

@Martin, I think its just an example. I'm sorry cant help in this topic. I dont use ci form_validation. I use regex to validate things like that.


RE: concat validation rules with form_validation - annx10 - 05-05-2017

Hi.

Yes, like marksman has said, max_length[15] for email was an example.
Then, if it is normal behaviour, everything cleared up, OK.
Anyway, I will use js validation before validation in server with Form_validation, so if there are several errors, will show all.

Thank you very much for acclarations.


RE: concat validation rules with form_validation - Martin7483 - 05-05-2017

(05-05-2017, 02:04 AM)annx10 Wrote: Hi.

Yes, like marksman has said, max_length[15] for email was an example.
Then, if it is normal behaviour, everything cleared up, OK.
Anyway, I will use js validation before validation in server with Form_validation, so if there are several errors, will show all.

Thank you very much for acclarations.

I use jQuery Form validation, but that also only shows one error per field.
I don't think it would make sence to show all requirements when a field fails


RE: concat validation rules with form_validation - InsiteFX - 05-05-2017

Errors stop on the first error found. So if you switched them around the other error would fire.


RE: concat validation rules with form_validation - annx10 - 05-06-2017

Quote:I use jQuery Form validation, but that also only shows one error per field.

I don't think it would make sence to show all requirements when a field fails

I consider that it is important show all error that user have had when form is full, because it is boring to fill out a form several times.

For example, imagine that you fill your username and now show that is very long (max_length[10]). You correct it and now show that that user exists (custom rule to avoid repeat usernames). You correct again and now show that username haven't correct format (you put a number in username that you don't permit with rule alpha).
I know that it is a rare situation, but it may occur, and if application had shown all error from the beginning, user could have corrected all the errors or avoid them.

I have too a form multipart with option to upload a image file.
That image file must be .png or .jpg, with max. resolution 400x400 and other limitations that I set with Upload class.
However, when I have an error in a field and in the image file, it shows field errors only, not for image file. Then, if I correct all error for fields, when I submit form again, now it shows errors for image file.

I suppose that for this situation, it's similar that Form_validation, it shows errors one at time.
Although I have:

PHP Code:
if( $this->form_validation->run() && $this->upload->do_upload('filename') )
{
    
// Process information
}
else
{
    
$errores validation_errors();
    
$errores .= $this->upload->display_errors();
    echo 
$errores;


When there are errors in fields and in the image file, it shows errors for fields only.


RE: concat validation rules with form_validation - skunkbad - 05-06-2017

Just for fun:

/****************************/
Errors:
1) You screwed up.
2) It was so bad we are laughing at you.
3) You must be a total idiot.
/****************************/


RE: concat validation rules with form_validation - annx10 - 05-12-2017

Many times users surprise us Wink