![]() |
Form_Validation and depend on fields...(again maybe) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Form_Validation and depend on fields...(again maybe) (/showthread.php?tid=23629) |
Form_Validation and depend on fields...(again maybe) - El Forum - 10-17-2009 [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 Form_Validation and depend on fields...(again maybe) - El Forum - 10-17-2009 [eluser]insub2[/eluser] Why not just do it like this? Code: if ($this->form_validation->run() == FALSE) Form_Validation and depend on fields...(again maybe) - El Forum - 10-17-2009 [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 Form_Validation and depend on fields...(again maybe) - El Forum - 10-17-2009 [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-guide/libraries/form_validation.html Form_Validation and depend on fields...(again maybe) - El Forum - 10-17-2009 [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-guide/libraries/form_validation.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 Form_Validation and depend on fields...(again maybe) - El Forum - 10-17-2009 [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. |