简体   繁体   English

一页上有3种重力形式

[英]3 Gravity Forms on one page

I'm currently displaying three gravity forms on a page, "display:none;", and setting them to "block" when one of the three corresponding buttons are clicked. 我当前在页面上显示三种重力形式“ display:none;”,并在单击三个相应按钮之一时将其设置为“ block”。

You can view the example on http://b2bsauce.com/ 您可以在http://b2bsauce.com/上查看示例

The problem is that on validation, the AJAX part reloads, with the error messages and again displays the form as hidden, which obviously, in this case, does not make sense. 问题在于,在验证时,AJAX部件将重新加载,并显示错误消息,并再次将表单显示为隐藏,这显然在这种情况下是没有意义的。

Is there any way I can hook into the validation process and set the form to display or should I have gone about this in another way? 有什么办法可以使我进入验证过程并设置要显示的表单,还是应该以其他方式进行?

JS JS

var form = jQuery(this).attr('href');
jQuery('.gform_wrapper').not(form).css('display','none');
jQuery(form).slideDown();

HTML HTML

Each form is contained in this wrapper, which is set to "display:none". 每个表单都包含在此包装中,该包装设置为“ display:none”。

<div class="gf_browser_chrome gform_wrapper" id="gform_wrapper_1" style="display: block;">
</div>

<div class="gf_browser_chrome gform_wrapper" id="gform_wrapper_2" style="display: block;">
</div>

<div class="gf_browser_chrome gform_wrapper" id="gform_wrapper_3" style="display: block;">
</div>

Submit buttons don't have the href attribute (assuming that's what is being clicked), are you trying to get the action of the form or just save the form instance itself to a variable? 提交按钮没有href属性(假设正在单击),您是要获取formaction还是只是将form实例本身保存到变量中?

I think you are trying to save the form element to a variable so I would change your code to: 我认为您正在尝试将form元素保存到变量,因此我将代码更改为:

var $form = jQuery(this).parents('form'); // use $ prefix to show it's a jQuery object
jQuery('.gform_wrapper').not($form).css('display','none');
jQuery($form).slideDown(); // not sure if you need this line if the form is already showing

but I'm not sure if that's all you need or not without some sort of self contained example that can be edited. 但是我不确定如果没有某种可以编辑的自包含示例,就可以满足您的所有需要​​。

Gravity forms can be a bit tricky at time and I eventually found the error. 重力形式有时会有些棘手,我最终发现了错误。

I used a "click" eventListener on the ".button" class to switch between hidden/block of the forms. 我在“ .button”类上使用了“ click”事件监听器,以在窗体的隐藏/块之间切换。 However, the submit button in Gravity Forms also has a button class attached, hence it was hiding the form every time the submit button was clicked. 但是,“重力表单”中的“提交”按钮还附加了一个按钮类,因此,每次单击“提交”按钮时,它都会隐藏表单。

I thus made sure that the click listener is only attached to the three buttons at the top. 因此,我确保单击侦听器仅附加到顶部的三个按钮。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM