Form validation has always been tricky and painful for developers since the Web was born. Before HTML5, it was a nightmare for developers to write lines of code for validating forms to get the desired information from the user.
In this chapter, we will cover the following topics:
<input>
and attributes used in validationsValidation of a form is a series of checks and notifications that guides a user as to what is required as an input while submitting information to a server. We can also say that it is a process of checking the input data against a specific standard or requirement.
Form validation is a process for detecting invalid control data and displaying those errors to the end users. The term has several benefits as follows:
Validation ensures that sufficient data has been provided by the user, such as with online shopping, which typically includes the address, e-mail address, and many more details which are mandatory for a transaction to be complete.
There are many methods to perform form validations, which can be categorized into the following:
Client-side validation can be performed using HTML5 attributes on a browser that supports them or even with the help of JavaScript for other browsers. HTML5 attributes reduce the effort of validation in comparison to cumbersome JavaScript validations.
The advantages of client-side form validation are as follows:
<form>
controls are filled by the user before submitting the form to the serverThe disadvantages of client-side form validation are as follows:
Various scripting languages, such as PHP, ASP, or Perl are used to screen and filter the data submitted by the user at server side.
This approach is used when we know that some checks can be performed only on the server side as security is required, as in the case of online shopping, where the user enters card details for making a payment.
The advantages of server-side form validation are as follows:
The disadvantages of server-side form validation are as follows:
More or less, we all have relied on JavaScript to validate forms. Also, we should always keep in mind that client-side form validation is not a replacement for foolproof server-side validation and handling errors. It is an efficient means of providing an instant feedback on the input of the user at the client end. In case of online shopping, the user selects total number of pieces, but after a certain limit, the user sees an error that the limit has been exceeded. All these validations demand high-end server-side validations, which is not possible on the client side. Always remember, in case of forms, use server-side validations.
13.59.13.210