Html 在浏览器中禁用表单验证

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9399528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:42:53  来源:igfitidea点击:

Disable form validation in browser

htmlinternet-explorerfirefoxgoogle-chromeopera

提问by Gerrit

I'm coding on a website with forms and use HTML5 validation - no rocket science so far. Everything works fine for me in Google Chrome, but I want to get sure that even a IE 6 user with no formvalidation does not insert malformed data into my MYSQL database.

我在一个带有表单的网站上编码并使用 HTML5 验证 - 到目前为止还没有火箭科学。在 Google Chrome 中一切正常,但我想确保即使是没有表单验证的 IE 6 用户也不会将格式错误的数据插入我的 MYSQL 数据库中。

Is there any way to turn off the HTML5 form validation in Google Chrome or some other state-of-the-art browser to test the serverside data validation?

有没有办法在 Google Chrome 或其他一些最先进的浏览器中关闭 HTML5 表单验证来测试服务器端数据验证?

回答by xyz

To disable validation in HTML5 use

要禁用 HTML5 中的验证,请使用

<form method="post" action="/foo" novalidate>...</form>

Refer thisquestion for more details.I think Junitcan also help to test server side validations.
Use parameterized query to gain more security. (If SQL query is formed using user input).

有关更多详细信息,请参阅问题。我认为Junit还可以帮助测试服务器端验证。
使用参数化查询来获得更高的安全性。(如果 SQL 查询是使用用户输入形成的)。



EDIT :

编辑 :

You can set it in About:flags
Steps:
1. On your Google Chrome address bar, type “about:flags” (without the quote) and press Enter.
2.Scroll down the list until you see the option “Disable HTML5 interactive form validation”.
3.Click the enable link.
Check : http://wikibin.org/articles/google-chrome-about-and-chrome-urls.html

您可以在 About:flags 中设置它
步骤:
1. 在您的 Google Chrome 地址栏上,输入“about:flags”(不带引号)并按 Enter。
2.向下滚动列表,直到看到“禁用 HTML5 交互式表单验证”选项。
3.单击启用链接。
检查:http: //wikibin.org/articles/google-chrome-about-and-chrome-urls.html



EDIT 2 :
Just came to know that About:flags is depreciated use Use chrome://flags instead. Thanks @Max.

编辑 2:
刚刚知道 About:flags 已折旧,请改用 chrome://flags。谢谢@Max。

回答by Bradley Flood

This Chrome extension allows you to disable Chrome's built in HTML validation

这个 Chrome 扩展允许你禁用 Chrome 的内置 HTML 验证

HTML5 Form validation errors remover

HTML5 表单验证错误移除器

回答by Matt3o12

Unfortunately, the accepted answer doesn't work anymore since it was introduced in case the form validation was buggy (see removal requests).

不幸的是,接受的答案不再起作用,因为它是在表单验证有问题的情况下引入的(请参阅删除请求)

Luckily, there is a chrome extension that does that for us for every page: Auto remove HTML5 form validation .

幸运的是,有一个 chrome 扩展可以为我们为每个页面执行此操作: 自动删除 HTML5 表单验证

I'm not the author of this plugin and I cannot guarantee you that it doesn't do anything it isn't supposed to. The source codeis very short, though (about 5 lines).

我不是这个插件的作者,我不能保证它不会做任何不应该做的事情。不过,源代码很短(大约 5 行)。

回答by zmechanic

It now requires novalidate="novalidate"as below:

现在要求novalidate="novalidate"如下:

<Form novalidate="novalidate" onSubmit={this.handleSaveFormSubmit}>

Just novalidateno longer works, and Chrome displays "Please fill out this field"

只是novalidate不再有效,Chrome 显示“请填写此字段”

回答by Diodeus - James MacFarlane

You should absolutelybe validating on the serverif you are building any SQL strings.

如果您正在构建任何 SQL 字符串,您绝对应该在服务器上进行验证。

In the client you should be able to fall-back to JavaScript-based validation, but that's no protection. Do it on the server as well.

在客户端,您应该能够回退到基于 JavaScript 的验证,但这不是保护。在服务器上也这样做。