Fill in those blanks
Forms are not a lot of good if your visitors forget to provide the really important information you want. Validation - checking the form - can make sure that your visitor's responses are there.
The most common problems you will have with forms are:
some answers you needed are left blank
some of the answers make no sense
Rejecting answers that make no sense ... such as a@b.c as an e-mail address .... require some fairly complex programming - far beyond the scope of this site. Search the web for 'javascript validation', and you'll find plenty of sites with help.
But the other problems is easily solved.
The only way to check your form's entries is to use javascript to test (some of) the form entries to see if they meet certain criteria.
If you are uncomfortable at the thought of working with simple javascripts, validation is very simple as long as you follow some simple rules.
Imagine that you have want to get the name of the person completing the form. You have a line in your form code like this:
<input type="text" name="visitor"> and you want to make sure that it's something has been entered there. Here's what you do.
When the user presses the form submit button, you want a check made that 'visitor' is not nothing. it could be anything, but you don't want it to be nothing.
You need some javascript to do that checking, and give the visitor a sensible message if they have left 'name' blank.
So, your 'standard' form needs a couple of additions - it needs a name, and it needs to perform an action when the submit button is pressed.
<form name="myform" onSubmit="checkData()" action="http:// blah blah .... >
This form opening line means that when the submit button is pressed, the javascript function called checkData is performed.
And a typical checkData script looks like this:
<script type="text/javascript">
<!--
function checkData() {
var correct = true
if (document.myform.visitor.value == "") {correct = false; alert("Please enter your name")}
return correct
}
//-->
</script>
So, if the value of the variable named visitor in the form called myform is equal to nothing, then give that alert and do not send the form ... otherwise everything is OK, and the form can be sent.
You can 'validate' more than one value in the validation script, and it's up to you to figure out how. Just be 100% certain that the name of the variable in the validation script is identical to the name of the variable in the form. For example, visitor and Visitor are different; email and Email are different.
Now you know how to ensure that any text fields in your form have something in them (might not make sense, but there will be something there).
Ensuring that a radio button or check box has been clicked, or that something has been chosen from a drop-down select list is more difficult - and frankly, it's beyond the scope of this site. [yes, I do know how to do it :)]
|