Note: You do not need to do the things mentioned in this article if you have created your feedback form using the Feedback Form Script Wizard.Among other things, the script made by the wizard automatically checks for empty fields.Sure, it may not look nice and tell you someone has been trying to mess with your script, but the important thing is he/she had failed! If you know exactly what kind of data to expect you can make further steps to ensure the user has entered what you want. Instead of writing the same code over and over again we can create a function that will do all the checking for us.We will cover a few samples like validating e-mail address and URLs later. Here we will name it check_input and simply call this function whenever we need to validate simple input data: Note the check_input function at the bottom.
If you have such a form on your site, I'm sure that from time to time, you would have received the results of your form with some essential field (like the email address or the visitor's name, or even the feedback itself) omitted. One way around it is to validate the essential fields with a simple Java Script.So, we need to always filter and validate the user entered before storing it in application’s database.In this article, we will learn how to perform basic validation of form in php.The ability to interact with, and obtain information from web site visitors, is a central theme behind the Java Script language.No Java Script book would be complete therefore, without exploring how to handle Graphical User Interface Components (GUI) objects such as buttons, text input fields, checkboxes, radio boxes and selections, together with the Form object which brings them all together. It acts a container for all of the GUI objects that make up a form.What it does is takes the data passed to the function, strips unwanted characters (extra space, tab, newline) from the beginning and end of the data using the PHP trim() function, strips any quotes escaped with slashes and passes it through htmlspecialchars().