Website forms offer users with a convenient way to communicate with you as a business owner. You can offer forms a wide variety of purposes throughout your web pages. Common forms include contact forms, sign-up forms and order forms. While adding forms to your website isn’t overly difficult, you should always work with your web development professional to ensure that simple form validation is implemented.
Simple form validation is used to validate data in HTML forms before sending the content to a server. JavaScript is commonly used for form validation. Form data is generally checked by JavaScript for the following:
- Did the user leave any required fields empty?
- Did the user enter a valid email address?
- Did the user enter a valid date?
- Did the user enter text in a numeric field?
While the above examples are not exhaustive by any means, they provide an idea of why simple form validation is important. Here is an example of Javascript form validation for required fields:
function validateForm()
{
var x=document.forms[“myForm”][“fname”].value;
if (x==null || x==””)
{
alert(“First name must be filled out”);
return false;
}
}
This function checks to see if a field has been left empty. If the field is left empty, an alert box comes up with a message, the function will return as false and the form will not be submitted to the server. If you want to add forms to your website, you’ll need to implement simple form validation to ensure that your forms are completed correctly by users prior to their submission. Remember to contact your web development professional for assistance in setting up your forms on your website.
Do you use forms on your website?