Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 'Required' attribute for form validation: Good idea or bad idea

Tags:

html

forms

html4

I am using the simplest of HTML 5 forms, and wish to use the 'required' attribute for the checkbox to make sure the user clicks it when submitting the form.

Should I have some server side validation - in case somebody is using a browser that doesn't support html5?

More Information:

My form looks like this:

[] I accept the terms and conditions

Submit

Code:

<input type="checkbox" required> I accept the terms and conditions<br />
<input type="submit" value="submit"/>
like image 227
accord_guy Avatar asked Aug 01 '16 09:08

accord_guy


People also ask

Which HTML5 attribute is used for data validation?

The pattern attribute of the <input> element allows you to add basic data validation without resorting to JavaScript. It works by matching the input value against a regular expression.

Which attribute is used for form validation?

The simplest HTML validation feature is the required attribute. To make an input mandatory, add this attribute to the element.

Does HTML5 have form validation?

Form validation can happen on the client side and the server side. Client side validation occurs using HTML5 attributes and client side JavaScript.

Which are the correct input restrictions used for validation purpose in HTML5?

Validation-related attributesThe value must be greater than or equal to the value. There must be a value (if set). Unless the step is set to the any literal, the value must be min + an integral multiple of the step. The number of characters (code points) must not be less than the value of the attribute, if non-empty.


1 Answers

Client-side form validation is a good way for enhancing user experience, it also provides some styling that can help to communicate that an input is required.

But you will allways still have to validate any data submitted on the server, making sure is clean and safe data. The required attribute can be manipulated by a malicious user.

like image 121
marcanuy Avatar answered Sep 21 '22 19:09

marcanuy