The username input field might therefore look like this:
<input name="username" type="text" size="50" maxlength="50">
And the comments textarea like this:
<textarea name="comments" cols="50" rows="10"></textarea>
The form tag line might look like the following. Be sure to substitute the path to the script you will use to process the form in the action attribute.
<form action="/cgi-bin/contactus.pl" method="post" name="submitForm" onsubmit="return validateForm(this)">
- A user fills in the fields in a form and then clicks on the submit button.
- The first subsection of the validateForm function checks to see if a value exists in the username field. If a value exists, the function continues to the next section. If it does not contain a value, the funtion displays an alert box, which prompts the user to enter a Name and places the cursor on the username field. A False value is also returned to the form, which prevents is from submitting the data to the script identified in the action attribute.
- Next, we use two routines to validate the e-mail field. The first somply check to see if a vale exists and handles it the same as with the username field. The second attempts to validate the format used for the e-mail address. This prevents someone from simply entering nonsense in the field.
- All valid e-mail addresses must have an "@" symbol, so it checks for that.
- All valid e-mail addresses must have at least one dot, so it checks for the existance of a dot.
- Commas are frequent typos, but are not allowed, so it checks for any commas.
- Spaces are not allowed, so i checks for a space.
- Finally, a valid e-mail address can be no shorter than 6 characters (firstname.lastname@example.org), so it checks the length.
- If all inspections pass, a True value is returned and the form sends the data to the e-mail processing script.