简体   繁体   English

重力形式的 Wordpress 中的 Bootstrap 模态

[英]Bootstrap Modal in Wordpress With Gravity Form

I have a page on a Wordpress site with a Bootstrap modal that appears when a graphic is clicked and inside the modal there is a Gravity Form.我在 Wordpress 网站上有一个页面,其中有一个 Bootstrap 模态,当单击图形时会出现该模态,并且在模态内有一个 Gravity Form。 When the page is first loaded, the Gravity Form code inside the modal causes some of my navigation links not to work.当页面第一次加载时,模态中的重力表单代码会导致我的一些导航链接不起作用。 I am fairly certain it is the combination of the php code that calls the Gravity Form (by calling it's short code) and the bootstrap modal window because when I remove the Gravity Form php code from the modal or remove the modal code and just display the form on the page the navigation links work properly.我相当确定它是调用 Gravity Form(通过调用它的短代码)和 bootstrap 模态窗口的 php 代码的组合,因为当我从模态中删除 Gravity Form php 代码或删除模态代码并只显示页面上的表单导航链接正常工作。

Any idea on why having a Gravity Form in a Bootstrap Modal would cause Wordpress navigation not to work?关于为什么在 Bootstrap Modal 中使用 Gravity Form 会导致 Wordpress 导航不起作用的任何想法?

Here is the site with the code on it: http://www.stlmaa.com/这是带有代码的站点: http://www.stlmaa.com/ : http://www.stlmaa.com/

Here is the button graphic code:这是按钮图形代码:

<img src="<?php bloginfo('template_directory'); ?>/images/questions.png" width="250px" data-toggle="modal" data-target="#myModal" style="cursor: pointer"/>

Here is the modal code:这是模态代码:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel" style="color:black">Contact Us!</h4>
</div>
<div class="modal-body" style="color: black; padding-top:-20px">
<?php echo do_shortcode('[gravityform id=1 name=ContactUs title=false description=false]'); ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>

I'm not entirely sure what you mean by "navigation issues". 我不确定您所说的“导航问题”是什么意思。 Everything seemed fine on the site in regards to navigation so I'm guessing you got that part resolved. 关于导航,网站上的一切似乎都很好,所以我想您已经解决了那部分。

If not and your referring to how the modal closes upon submission, I would recommend that you add an additional ajax attribute to your shortcode so that that the form will stay open. 如果不是这样,并且您指的是提交后模态如何关闭,我建议您向您的简码添加一个额外的ajax属性,以使表单保持打开状态。 This will make sure that your user knows all appropriate fields are filled out, and it gives them the confirmation. 这将确保您的用户知道所有适当的字段都已填写,并向他们提供了确认。 You would also want to remove the "name" field; 您还希望删除“名称”字段; just make sure you have the right number in the form ID. 只要确保您在表单ID中输入正确的数字即可。 It should look like this: 它看起来应该像这样:

<?php echo do_shortcode('[gravityform id="1" title="false" description="false" ajax="true"]'); ?>

source: https://www.gravityhelp.com/documentation/article/embedding-a-form/ 来源: https : //www.gravityhelp.com/documentation/article/embedding-a-form/

Does that resolve your issue? 这样可以解决您的问题吗?

I know this post is SUPER old but it is indexed in Google, so just in case anyone else comes across this during your searches....我知道这篇文章已经过时了,但它已在 Google 中编入索引,以防万一其他人在您的搜索过程中遇到此问题....

You do need to use ajax, or submitting the form will close the modal and redirect you to a new page.您确实需要使用 ajax,否则提交表单将关闭模式并将您重定向到新页面。

However;然而; to stop the modal from closing the change isn't with the shortcode embed (in fact you should be using the function, NOT the shortcode as per the same URL posted by @ahurleb) but rather the change is with the bootstrap option values.阻止模态关闭更改不是使用短代码嵌入(事实上,您应该使用该函数,而不是使用@ahurleb 发布的相同 URL 的短代码),而是使用引导选项值进行更改。 You can make the form persist and have another button set to close manually or when clicking outside the bounds of the modal.您可以使表单持久化,并将另一个按钮设置为手动关闭或在模式边界外单击时关闭。

For the function to properly embed the gravity form, see here: https://docs.gravityforms.com/adding-a-form-to-the-theme-file/有关正确嵌入重力形式的功能,请参见此处: https : //docs.gravityforms.com/adding-a-form-to-the-theme-file/

gravity_form( $id_or_title, $display_title = true, $display_description = true, $display_inactive = false, $field_values = null, $ajax = false, $tabindex, $echo = true );

To understand the bootstrap modal and how to make it persist, see here : prevent bootstrap modal window from closing on form submission要了解引导模式以及如何使其持久化,请参见此处: 防止引导模式窗口在提交表单时关闭

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

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