November 2, 201016 yr I have a web form on a HTML page and a JavaScript file that is lived to that page. The JavaScript file preforms some validation on the form, so that when a text box is selected a help message is shown, if it is left empty anouther message is shown. The form (using the post method) is then sent to a PHP file to add its contents to a database. Although the JavaScipt file is letting the user know in real time if the fields of the form are incorrect or left blank, once the submitt button is clicked the PHP page is called and the data is added to the batabase, even if there is a problem with the validation. What I want is when the button is clicked, if there is a problem, the messages stay there, possiably anouther new message shown and the page does not leave the current one and go to the PHP one to add to the database. Any ideas?
November 2, 201016 yr Client-side validation (from JavaScript) isn't enough. As you've noticed, once you get past it, any data is sent to the database. What you need to do if check your data again server-side (in PHP) and only if it passes that test do you add it to the database. There are ways of combining the two so that real-time validation can be matched with server-side security. The best tutorial I've ever found that describes that was written by Christian Heilmann. If it all seems too complex, just check it a second time
Create an account or sign in to comment