如何让这个表单只在它应该提交的时候提交
How to get this form to submit only when it should
可能是个愚蠢的问题,但我发现这真的很棘手:
我试图让表单仅在特定情况下提交。
每次我在我的页面中提交任何其他表单时,下面的脚本都会执行。
我怎样才能让它不执行,除非它被调用?
$('#nurturing_pop_up_form').validate({
rules: {
emailaddress: {
required: true,
email: true
},
board_meeting: {
required: {
depends: function () {
return $('input[name=in_12_months]').is(':checked')==false && $('input[name=in_6_months]').is(':checked')==false
}
}
}
},
submitHandler: function(form) {
var url_remind = 'http://example.com';
var data_remind = $('#nurturing_pop_up_form').serializeArray();
$.ajax({
type: "POST",
url: url_remind,
data: data_remind,
success: function(){
$('.nurturing_pop_up').fadeOut();
}
});
}
});
我应该添加这样的内容吗?
$('#nurturing_pop_up_form').submit(function(e){
e.preventDefault();
$('#nurturing_pop_up_form').validate({
rules: {
//the rest like above
非常感谢您的帮助!
I am trying to make a form submit only when it specifically should.
此过程由 jQuery 验证自动 处理。您应该不做任何特殊的事情来强制执行此操作。
The script below executes every time I submit any other form in my page.
脚本"below",.validate({...})
,只是插件的初始化例程。在您显示的代码中,您仅使用 id="nurturing_pop_up_form"
初始化一个表单。页面上的其他表单将完全不受影响。也许您有无效的 HTML、.validate()
的其他实例、其他提交处理程序,或者您没有向我们展示的一些错误代码。
How can I make it not execute, unless it is called for?
我认为你的问题是基于对正在发生的事情的错误假设。 .validate()
只应在页面加载时调用一次(DOM 就绪处理程序)以 初始化 表单上的插件。插件随后 自动 捕获点击、验证数据并处理提交。
Should I add something like this?
$('#nurturing_pop_up_form').submit(function(e){
e.preventDefault();
$('#nurturing_pop_up_form').validate({...
绝对不行。您应该永远不要将.validate()
放在同一个表单的.submit()
处理程序中。完全没有必要,延迟插件的初始化,并干扰内置的提交处理程序。
您所显示的任何内容都无法解释 how/why 其他表格会受到影响。
可能是个愚蠢的问题,但我发现这真的很棘手:
我试图让表单仅在特定情况下提交。 每次我在我的页面中提交任何其他表单时,下面的脚本都会执行。
我怎样才能让它不执行,除非它被调用?
$('#nurturing_pop_up_form').validate({
rules: {
emailaddress: {
required: true,
email: true
},
board_meeting: {
required: {
depends: function () {
return $('input[name=in_12_months]').is(':checked')==false && $('input[name=in_6_months]').is(':checked')==false
}
}
}
},
submitHandler: function(form) {
var url_remind = 'http://example.com';
var data_remind = $('#nurturing_pop_up_form').serializeArray();
$.ajax({
type: "POST",
url: url_remind,
data: data_remind,
success: function(){
$('.nurturing_pop_up').fadeOut();
}
});
}
});
我应该添加这样的内容吗?
$('#nurturing_pop_up_form').submit(function(e){
e.preventDefault();
$('#nurturing_pop_up_form').validate({
rules: {
//the rest like above
非常感谢您的帮助!
I am trying to make a form submit only when it specifically should.
此过程由 jQuery 验证自动 处理。您应该不做任何特殊的事情来强制执行此操作。
The script below executes every time I submit any other form in my page.
脚本"below",.validate({...})
,只是插件的初始化例程。在您显示的代码中,您仅使用 id="nurturing_pop_up_form"
初始化一个表单。页面上的其他表单将完全不受影响。也许您有无效的 HTML、.validate()
的其他实例、其他提交处理程序,或者您没有向我们展示的一些错误代码。
How can I make it not execute, unless it is called for?
我认为你的问题是基于对正在发生的事情的错误假设。 .validate()
只应在页面加载时调用一次(DOM 就绪处理程序)以 初始化 表单上的插件。插件随后 自动 捕获点击、验证数据并处理提交。
Should I add something like this?
$('#nurturing_pop_up_form').submit(function(e){
e.preventDefault();
$('#nurturing_pop_up_form').validate({...
绝对不行。您应该永远不要将.validate()
放在同一个表单的.submit()
处理程序中。完全没有必要,延迟插件的初始化,并干扰内置的提交处理程序。
您所显示的任何内容都无法解释 how/why 其他表格会受到影响。