Welcome Guest, Not a member yet? Register   Sign In
concat validation rules with form_validation
#1

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.
Reply
#2

(This post was last modified: 05-04-2017, 02:05 PM by Martin7483.)

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?
Reply
#3

@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.
God Bless CI Contributors Smile
Reply
#4

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.
Reply
#5

(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
Reply
#6

Errors stop on the first error found. So if you switched them around the other error would fire.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

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.
Reply
#8

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.
/****************************/
Reply
#9

Many times users surprise us Wink
Reply




Theme © iAndrew 2016 - Forum software by © MyBB