Problem with Validation when using an image submit button |
[eluser]Oussama M Billah[/eluser]
Hello, I m having a form with an image submit button. When filling the form and clicking the submit button the form is correctly validated. However, when i fill the form and press the enter button the form is not validated and the same page is reloaded with no error msg. when I use a plain submit button ( no image ) everything works fine. the only difference between the two type of submit buttons is that when using an image I add '_x' to the submit button name in the controller. What can be the problem that causes the form to not validate when pressing the enter button. Thanks
[eluser]Oussama M Billah[/eluser]
here is the controller : Code: function index(){ here is the form code in my view: Code: <div class="register_error">
[eluser]Aken[/eluser]
1) Your problem is that when you hit the enter key, the name value of the image does not transfer in with the rest of the form variables. 2) You should not check for a post variable to see if the form is submitted. The form_validation->run() function does that for you. Read the form_validation page carefully, it explains how to check for that very thing. 3) You don't need to load the form_validation library again in your view. Once in the controller is sufficient. 4) You can use custom functions called callbacks as a rule when validating a form. You should consider using that for checking if the username exists instead of using flashdata and redirects. 5) When doing redirects, you don't use the return property with them. You should also use the exit; property right after a redirect. Your code seems to work, but it can be cleaned up a lot. Those are good places to start.
[eluser]Oussama M Billah[/eluser]
Thanks Aken, This is my first application in php & codeIgniter so the code may not be perfectly clean. Will fix the small problems based on your suggestions. Thanks again. |
Welcome Guest, Not a member yet? Register Sign In |