Form validation with JavaScript |
|
|
|
|
The HTML markup language has build in codes to provide forms. In forms the user can input fields fill out, in text fields of several lines text enter, from lists of entries selects and so forth.If the form is filled out, the user can click on a Button, in order to process the form. The form contains special tags to indicate what happens with the data of the filled out form. For example send the data by E-Mail or process the data with a CGI program on the server.Generally, the major problem is the form validation.
php form validation tutorialThe HTML markup language has build in codes to provide forms. In forms the user can input fields fill out, in text fields of several lines text enter, from lists of entries selects and so forth.If the form is filled out, the user can click on a Button, in order to process the form. The form contains special tags to indicate what happens with the data of the filled out form. For example send the data by E-Mail or process the data with a CGI program on the server.Generally, the major problem is the form validation. So what is form validation ?Form validation the process that occurs after the user clicks the submit button and before the form data processed by a PHP, JAVA or CGI program. In this tutorial, you'll learn how to intercept the submission and pass the form data through one validation tests. At the end of this tutorial, you´ll have a complete form validation framework in php wich can be seemless integerate in existing web applications. html forms howtoConstructing a form is quit more easy as it appears first. If you've familiar with HTML, then you'll be quick at learning setting up forms. Because forms just some special HTML tags embedded right in a ordinary HTML page. Forms start with the <FORM> tag. All form elements embedded between the opening <form> and closing </form> tag. The area between the form tags consists of html tags. <form parameter> The form tag has two important attributes: action="handlerpage" method ="GET|POST" For a complete reference take a lock at the HTML 4.01 specification. Look at this small example: <form method="post" action="process.php"> This example asks for a user name and e-mail address and submit the data to a php script called process.php. For further help on html forms see the html form tutorial from Ray Fischer JavaScript form validationForm validation with JavaScript is a self-suggestion way to validate form data. To understand the difference from JavaScript validation to the active-form framework, I´ll explain in short how to validate forms with JavaScript. Form validation with JavaScript is called client side validation, because the validation is done at the client side. Validating forms on the client lightens the load on the server and allows you to check the form data before it is sent for processing. function validator() For this example, I wrote a JavaScript function validator(). The purpose from validator() is to check if aTextField is empty. The form example executes the JavaScript function validator() before the default action processor.php is called. Unfortunately, writing client-side validation in this way is error prone and intricately. A little relief is a generic reusable validation script. For example the JavaScript validation framework from Prasanth M J. So what is the snag ?
Server-side validationIn contrast to client side form validation, the server side form validation will be done after the form is submitted. If one or more form fields invalid, well´ll have to show the input form, together with an error message, again. At the beginning I defined the major requirements for a generic form validation framework. It is called: active-forms The active-forms framework meets three conditions:
|
| < Prev | Next > |
|---|