暂时关闭cakePHP表单上的所有验证以提交ajax请求? [英] Temporarily switch off all validation on cakePHP form to submit ajax request?

查看:105
本文介绍了暂时关闭cakePHP表单上的所有验证以提交ajax请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery文件上传(蓝色imp),并将其用作表单上的上传字段。在窗体上触发点击上传验证(即 - 字段X为空等等)。

I'm using jQuery file upload (blue imp) and using it as an upload field on a form. On clicking upload validation is triggered on the form (ie - field X is empty and so on).

替代方法是将ajax提交放到结尾,但不是直观地输入表单 - 对用户显示无序。

Alternatives are place the ajax submissions at the end, but that is not intuitive when entering a form - things appear "out of order" to the user.

不知道如何解决这个问题。

Not sure how to address this. Is the upload field then actually a form and I should treat it as such?

推荐答案

jQuery文件上传(蓝色imp)是一个表单,使用提交按钮创建表单。如果你在你的视图中使用它自己的形式,它本质上变成一个嵌套的形式是无效的HTML。浏览器将您的上传提交按钮视为提交到原始表单的按钮。
如果是这种情况,您必须删除上传按钮并将其放在您的原始表单之外。

The jQuery file upload (blue imp) is creating a Form with a submit button. If you use it in your view within your own form, it essentially becomes a nested form which is invalid HTML. The browser considers your Upload submit button as the submit button to your original form. If this is the case, you will have to remove the upload button and put it outside your original form.

如果您只想删除所需的标签和来自浏览器的客户端验证,然后假设您使用Cake 2.3+:
请参阅 book

If you want to simply remove the required tags and the client validation that comes from the browser, then assuming you are using Cake 2.3+: Refer to the following section in the book.

您可以为了跳过浏览器验证触发的整个窗体,你可以设置选项'formnovalidate'=> true为您生成的输入按钮使用FormHelper :: submit()或set'novalidate'=> true FormHelper :: create()的选项

"You can explicitly set required key in options array to override it for a field. To skip browser validation triggering for the whole form you can set option 'formnovalidate' => true for the input button you generate using FormHelper::submit() or set 'novalidate' => true in options for FormHelper::create()"

这篇关于暂时关闭cakePHP表单上的所有验证以提交ajax请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆