Welcome Guest, Not a member yet? Register   Sign In
matches in form_validation seeming to fail.
#1

hi, I am super new to codeigniter, and loving it so far. I apologize in advance, if this has been addressed in another post already. I have done some searching already, and was unable to see this same issue I have run into.

for some reason, it appears that the form_validation is failing when trying to match my 2 password fields. i have changed the "type" from "password" to "text" so that i could see whats being typed in the field, and I also output the error in an object.

[Image: EjlGLXu.jpg]

{"result":0,"error":{"password":"The Password field does not match the confirm_password field."},"password":"test01","confirm_password":"test01"}

anyone seen this problem using "matches" in the form_validation?
Reply
#2

What does the code for your form/view look like? What are your validation rules?

As long as both fields match, I haven't had any trouble with the "matches" rule on password fields, but you do have to setup the form and validation rules properly.
Reply
#3

(08-24-2015, 08:56 AM)mwhitney Wrote: What does the code for your form/view look like? What are your validation rules?

As long as both fields match, I haven't had any trouble with the "matches" rule on password fields, but you do have to setup the form and validation rules properly.

Thanks for your response. I will post just the validation rules for the password, the other 4 seem to work fine, it's only the "matches" in my confirm_password field.

in my controller:
<MyCode>$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]|max_length[32]|matches[confirm_password]');</MyCode>

in my view:
<MyCode><input type="text" name="password" class="form-control" placeholder="Password" />
<input type="text" name="confirm_password" class="form-control" placeholder="Confirm Password" /></MyCode>
Reply
#4

That should work, as long as the fields are being posted by the form and no other code in the controller is messing things up by changing the posted data or passing different data to the form_validation library (or some other rule is modifying one of the password fields).

Honestly, the only thing I can really say with the code I've seen so far is to make sure the HTML for your form is coming out right in the browser (it's fairly common for someone to nest divs improperly and break out of their form earlier than they intended) and make sure the values of the two password fields aren't modified before (or during) validation.
Reply
#5

try adding a validation rule for the 'confirm_password' field, make it required etc
Reply
#6

(08-24-2015, 02:58 PM)cartalot Wrote: try adding a validation rule for the 'confirm_password' field, make it required etc

Hey cartalot..

That seemed to work! Thank you!!

Thank you to mwhitney too!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB