简体   繁体   English

用于表单验证的HTML5“必需”属性:好主意或坏主意

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

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. 我使用最简单的HTML 5表单,并希望使用复选框的“required”属性,以确保用户在提交表单时单击它。

Should I have some server side validation - in case somebody is using a browser that doesn't support html5? 我是否应该进行一些服务器端验证 - 如果有人使用不支持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"/>

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. required属性可由恶意用户操纵。

Actually required CSS pseudo class is supported by all browser (no ok, IE8 excluded), as you can see here 实际上所有浏览器都支持CSS伪类(不行,IE8除外),你可以在这里看到

http://caniuse.com/#search=form%20validation http://caniuse.com/#search=form%20validation

Anyway, you ALWAYS need a server side validation, because client side checked data must be considered unsafe regardless. 无论如何,您总是需要服务器端验证,因为客户端检查的数据必须被视为不安全。

永远不要相信客户端的任何数据(无论是HTML还是JS,都可以更改。客户端验证只是为了获得更好的用户体验。真正的安全性在于服务器端。

It is not enough to save your logic behind the UI. 将您的逻辑保存在UI后面是不够的。 Some HTML form validation dose not work in some browsers . 某些HTML表单验证在某些浏览器中不起作用 So server side validation is MUST! 所以服务器端验证必须!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 网页形式的html5必需属性验证组 - html5 required attribute validation group in web form <sup>在必需的表单字段中</sup>使用<sup>标签-好主意吗?</sup> - Using <sup> tag for required form fields--good idea? 带有必需和禁用元素的Html5表单验证 - Html5 form validation with required and disabled element 仅HTML5-复选框输入上的“必填”属性可防止验证失败后重新提交表单 - HTML5 only - 'Required' attribute on checkbox input preventing form from being resubmitted after validation fail 应用选择菜单的表单验证类似于的html5必需属性<input> - Applying form validation of select menu similar to html5 required attribute of <input> 使用document.getElementsByTagName()是个好主意还是坏主意? - Is using document.getElementsByTagName() a good idea or bad idea? 使用新的HTML5验证/必需的输入功能是一件坏事吗? - Using new HTML5 validation/required input features a bad thing? 在Django必需的表单字段上防止html5“ required”属性 - Prevent html5 “required” attribute on Django required form fields 必需属性HTML5 - Required attribute HTML5 更改CSS样式HTML5表单所需的属性所需的消息 - Change css style HTML5 form required attribute required message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM