Search the Community
Showing results for tags 'form-validation'.
-
Complete php newb here. I'm trying to run 3 different form validation scripts - one to validate the basic info fields (check if they're empty etc.) one to verify a credit card number, and the last one is a CAPTCHA. The validation scripts is on the same page as the form and are set to run when the submit button is clicked. The basic format is if validate1(parameters) { // display errors } else { $validate1pass = true; } if validate2(parameters) { // etc... } Where $validate1pass is declared at the beginning of my php code as false. The idea was for each function to set it's pass variable to true, so the form action (using post method) would check to see if validate1pass && validate2pass && validate3pass == true and if it is echo the location of my success page. Here's what happens - if there are any errors, everything works great and the page reports the them. However if the form is filled out perfectly, it just reloads. No error messages, and no data in the fields. The variables are apparently now all set to true, since clicking the submit button again, no matter what the form data is goes to my success page witch gets any data entered. Curious, I added an else argument in the form action line to send me to a non-existing page. I tried it again - entered data wrong, got corrected, entered it right and 404. I think the problem is that the button that trigers all my validation functions is the submit button, and it ends up trigering the form action first, which ends up being "". So is this 3 boolean variables approach completely wrong (in which case what would be a good alternative?), or can it be fixed? Would it be possible to make an invisible submit button and have my script trigger that one after the variables are set?
- 3 replies
-
- php
- form-validation
-
(and 2 more)
Tagged with: