Form_Validation and depend on fields...(again maybe) |
[eluser]hugle[/eluser]
Hello CI community! I came to a problem, where I need to let a person change his email. So I require a member, to write down and old email, and the new one, he wants to... here is the short version of the controller: Code: $this->form_validation->set_rules('oldemail', 'Old email', 'strip_tags|trim|xss_clean|required|valid_email|dx_check_old_email'); I think, all the rules are understandable, in "oldemail" the rule: dx_check_old_email - returns TRUE if user entered correct OLD email in: "New email" - dx_is_email_available - return TRUE if email is not already taken by anyone else and.. dx_change_email - changes the email. The problem is in rule 'dx_change_email' I need to run it, just only, if rule 'oldmail' returned NO ERRORS after all rules passed... is there a way to somehow test it? I looked into some sugestions on the forums, but seems they doens't meet me... so It looks like: dx_change_email[dependson.oldemail] I don't know really how it could look like... Thanks a lot guys, for looking into my app! cheers, huglester
[eluser]insub2[/eluser]
Why not just do it like this? Code: if ($this->form_validation->run() == FALSE)
[eluser]hugle[/eluser]
[quote author="insub2" date="1255811760"]Why not just do it like this? Code: if ($this->form_validation->run() == FALSE) well, your approach isn't correct, just because... I want to change email in form validation rule: dx_change_email in your approach, email would be changed, even if old email returns FALSE after each rule... Thanks for looking into my problem
[eluser]insub2[/eluser]
umm...no. if any of the rules you set aren't matched, the validation will return false. http://ellislab.com/codeigniter/user-gui...ation.html
[eluser]hugle[/eluser]
[quote author="insub2" date="1255813852"]umm...no. if any of the rules you set aren't matched, the validation will return false. http://ellislab.com/codeigniter/user-gui...ation.html[/quote] yes, but I want to check if only field1 - returned false or true, inside extended form validation rule...(not all the fields) That's what I am trying to achieve. but seem it is quite difficult to achieve, so I probably will go with smth similar to your suggestion. Thanks
[eluser]insub2[/eluser]
Oh, you hadn't mentioned that you wanted the email to change regardless of other, unmentioned, fields validating or not. Though I don't think that it is necessarily best for the user, you could try having dx_check_old_email set something like $this->old_email_bool to TRUE of FALSE. Then send that to dx_change_email by dx_change_email[$this->old_email_bool] (Source for more info) The trick here is mostly how you have dx_check_old_email set the var so that it is readable inside your controller. |
Welcome Guest, Not a member yet? Register Sign In |