Welcome Guest, Not a member yet? Register   Sign In
Validation error messages below or beside fields

(This post was last modified: 04-21-2018, 06:55 PM by danangeloalcanar.)

Hi CI community,

I have a simple question, but I can't produce the answer however I tried to think of it.

Here is my scenario:

I have a registration form. So users fill it out.

Now, if the validation criteria was not satisfied, the form will show validation errors right? 
<?php echo validation_errors(); ?>
The error messages will display above the form, right?

Now, here is what I want to accomplish. 

I want to show the error for each field, just below the field.

For example, I have a validation rule for the username, that it must be at least 6 characters long. If the user inputs 4 characters only,
I want the error to show just below the field. 

So if  I have error messages for username field and password field, the error messages for the username field will show below the username field, and the error messages for the password field will show below the password field. at the same time.

Now, here's a solution I am thinking but I don't know if it is the right way.

I will just set a flashdata for each field? and if it is set, I will just show it  like this:

if ($username < 6) {
    $this->session->set_flashdata('is_less_than_six', 'Username must be at least 6 characters long.');

And then create a span element below the username field:
if ($this->session->flashdata('is_less_than_six')) {
    echo $this->session->flashdata('is_less_than_six');

Is that a good solution? We know it will work, but how about repopulation the fields?

Hope you can guide me guys. I want to make my validation errors understandable to the users. Thankyou.



Messages In This Thread
Validation error messages below or beside fields - by danangeloalcanar - 04-21-2018, 06:53 PM

Theme © iAndrew 2016 - Forum software by © MyBB