![]() |
Form Validation - Requiring one input OR the other - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Form Validation - Requiring one input OR the other (/showthread.php?tid=13927) |
Form Validation - Requiring one input OR the other - El Forum - 12-11-2008 [eluser]gstjohn[/eluser] I'm new to CodeIgniter, but love it already. Was hoping to get a hand with some confusion with the form validation. Best as I can tell there is nothing about it specifically on this forum. I have a form that collects city and state OR zip code. I can't for the life of me figure out how to validate this with CI. Obviously just using required for all three doesn't cut it since it's an OR situation. Best as I can tell a callback won't work either. Am I just being ridiculous and not seeing the solution? If there is no way to check this with the validation library, how would I validate it myself and push the error message to the view? Thanks in advance! Form Validation - Requiring one input OR the other - El Forum - 12-12-2008 [eluser]missionsix[/eluser] use an if statement to check if the fields are filled, before you build your requirements. As such: Code: <?php Rules are set after the form is sent to the browser, so you still have access to $_POST vars from there in ($this->input->post(KEY); ). Hope that helps. Form Validation - Requiring one input OR the other - El Forum - 12-12-2008 [eluser]gstjohn[/eluser] Wow! Duh... That seems so obvious after having seen it. Definitely appreciate the direction! Form Validation - Requiring one input OR the other - El Forum - 12-12-2008 [eluser]gstjohn[/eluser] Small note: empty() cannot check the return value of a function or method. Code: if (empty($this->input->post('zipcode'))) { ... } You will get an error saying: Quote:Fatal error: Can't use method return value in write context in ... Corrected syntax will need to be: Code: $zipcode = $this->input->post('zipcode'); |