gpt4 book ai didi

jquery - MVC 绕过客户端验证 ("save progress"与 "submit")

转载 作者:行者123 更新时间:2023-12-01 02:11:13 24 4
gpt4 key购买 nike

我有一个表单,我希望能够在不验证的情况下保存它,但在提交时进行验证。此表单上有两个按钮,用于保存或提交。

问题是:如果我使用“提交”按钮保存(然后在 Controller 中切换哪个操作),jquery.validate 就会启动,并且我无法保存部分填写的表单。

如果我将其作为链接,我不知道如何使表单发布到 Controller 中的新操作。

这是 View 中的 HTML:

<a class="btn  btn-default" data-placement="right" data-title="Save your progress." href="/Summary/Save/2" rel="tooltip"><i class="glyphicon glyphicon-floppy-disk"></i> Save Summary</a> 
<a class="btn btn-default" confirm="Are you sure you want to revert to the previous saved copy? You will lose all changes since your last save." data-placement="right" data-title="Revert back to your last saved copy." href="/Summary/Revert/2" rel="tooltip"><i class="glyphicon glyphicon-remove"></i> Revert Changes</a>
<button class="btn-default btn btn-primary" confirm="This will submit the summary to the evaluator for review. No changes will be allowed unless the evaluator returns it. Are you sure?" type="submit">Submit Summary</button>

最佳答案

顺便说一句,根据 Skipping validation on submit 上的文档,当前答案已被弃用。 :

To skip validation while still using a submit-button, add the attribute "formnovalidate" to that input:

<input type="submit" name="go" value="Submit">
<input type="submit" formnovalidate name="cancel" value="Cancel">

This used to work by adding class="cancel" to the input, this is now deprecated.

尽管从版本 1.17 开始,这两种方法仍然出现在 source code 中:

...blob/1.17.0/src/core.js#L34:

// Allow suppressing validation by adding a cancel class to the submit button
if ( $( this ).hasClass( "cancel" ) ) {
validator.cancelSubmit = true;
}

// Allow suppressing validation by adding the html5 formnovalidate attribute to the submit button
if ( $( this ).attr( "formnovalidate" ) !== undefined ) {
validator.cancelSubmit = true;
}

进一步阅读:jQuery Validation plugin: disable validation for specified submit buttons

关于jquery - MVC 绕过客户端验证 ("save progress"与 "submit"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21007711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com