Welcome Guest, Not a member yet? Register   Sign In
Form re-population
#1

[eluser]xerosis[/eluser]
I have a question regarding form re-population.

Basically I request from users firstname, lastname, email, password.

Now if the user does not do the regular:
Code:
$this->form_validation->set_rules('firstname', 'firstname', 'trim|required');
$this->form_validation->set_rules('lastname', 'lastname', 'trim|required');
$this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'password', 'trim|required|min_length[6]|max_length[12]|matches[passconf]|md5');
$this->form_validation->set_rules('passconf', 'passconf', 'trim|required|min_length[6]|max_length[12]');

it returns and the form fields get re-populated, but there is a case where the form validation does happen meaning user has done all of the above, but I need to do a second check and make sure that this email was not used before, now if the email was used before then it is as if the form_validation did not go through, it must return to the register page and fill re-populate stating a different error. In this case it does not get re-populated. How can I fix this issue?

Thanks.
#2

[eluser]Adrian Walls[/eluser]
Why not use a callback to extend the validation process and check if the email exists

http://ellislab.com/codeigniter/user-gui...#callbacks
#3

[eluser]xerosis[/eluser]
Yes, a callback can work in cases where I want to check if username is taken or not.

Now what if I am creating a login page and need a mix of two fields.
For example I need to check username + password and make sure a user exists, if it does not exist return back with an error, filling the username with what the user has placed.
#4

[eluser]Adrian Walls[/eluser]
This is more than form validation. Form validation should not really be used to check a login is correct. The form validation should check that the user has entered a username and password and some perform some basic validation i.e. password is x chars long, contains a number etc or whatever other input rules you want to enforce.

If the validation passes then in this portion of the if statement you can proceed to make a call to your model to check the username and password exists in the database knowing that someone has entered a username and password in the correct format. If not then I suggest assigning back the post variables in an array to the view and you can also set your own message. This doesn't really belong to either field as is a result of two inputs but you could if you wanted just assign it back to the username field error or a custom error div at the top of the login form.

Hope that makes sense.
#5

[eluser]xerosis[/eluser]
I actually have a custom error div which reads the validation_errors() and displays accordingly.

I was hoping I could send the error as validation_errors() as to not have to create the same div for a flasherror.




Theme © iAndrew 2016 - Forum software by © MyBB