form_validation and multiple forms |
[eluser]theprodigy[/eluser]
I apologize if this has already been asked. My quick forum search didn't turn up anything. When running form_validation on a page that has multiple forms (both login and registration are on same page), how can I tell which form to run validation? normally I: Code: $this->load->helper('form'); I know that I can separate which set of rules to call when running $this->form_validation->run(), but with multiple forms on the page, do I call it twice (or as many times as there are forms on the page)? do I do Code: if($this->form_validation->run('login') == FALSE && $this->form_validation->run('register') == FALSE) Thanks for any and all help
[eluser]Phil Sturgeon[/eluser]
Form_validation library just checks the $_POST super-global variable so whatever in there is validated. To find out which form was posted, you can either set the action attribute to go to two totally different controller methods (URL's) or you can do it based on the submit button. Code: if($this->input->post('loginSubmit')) Those would just be set with: Code: <input type="submit" name="loginSubmit" id="loginSubmit" /> or of course use the form helper. It's all the same. :-)
[eluser]theprodigy[/eluser]
I thought about sending them to two different controller functions, but wouldn't that make it difficult should they fail the validation? -----Example:----- http://www.example.com shows two forms. One goes to /login and one goes to /register. They fill out the registration form, and click submit. Oops! password is not long enough. What do I do now? Do I redirct back to http://www.example.com passing form field data back to re-populate the form? Do I leave it at /register but show the same view over again, so that both /register and / are essentially the same page (and same with /login)? Something else entirely I haven't mentioned? -----End Example----- If I don't send to different functions, then how would I handle the multiple form submissions? I thought about doing the Code: if($this->input->post('login')) Code: <?= validation_errors(); ?> Thanks
[eluser]Phil Sturgeon[/eluser]
Code: <?php if(validation_errors()) echo validation_errors(); ?> |
Welcome Guest, Not a member yet? Register Sign In |