简体   繁体   English

如何在联系表格 7 中提交表格后显示 div

[英]How to show a div after form submission in contact form 7

I need to show a div with some contents only after submission of form.我只需要在提交表单后显示一个包含一些内容的 div。 For form I am using contact form 7. After submitting the form I am redirecting to this link "https://example.com/referr-mobile-app/#wpcf7-f651-o1" and here I want to display that div.对于表格,我使用的是联系表格 7。提交表格后,我将重定向到此链接“https://example.com/referr-mobile-app/#wpcf7-f651-o1”,在这里我想显示该 div。 Please anyone help?请任何人帮助?

UPDATE 1 :更新 1

You can manage this using javascript and css.您可以使用 javascript 和 css 进行管理。

Try out this code in your theme's js file.在主题的 js 文件中试用此代码。

jQuery('.wpcf7-form').prepend('<div class="form_sent_msg">Thank you for your message.</div>');

also add this css for show/hide the div on form sent.还添加此 css 以显示/隐藏发送表单上的 div。

.form_sent_msg{
    display:none;
}

.wpcf7-form.sent .form_sent_msg{
    display:block;
} 

UPDATE 2 : try out this code for your custom post type field to insert above the form.更新 2 :尝试将此代码用于您的自定义帖子类型字段以插入到表单上方。

add_action('wpcf7_mail_sent', function ($cf7) {
    add_action('wp_footer', function(){
        global $post;
        $custom_field = get_field('custom-field', $post->ID);
        ?>
        <script>
            (function ($) {
              $(document).ready(function () {
                $('.wpcf7-form').prepend('<div class="form_sent_msg">'+ '<?php echo $custom_field;?>' +'</div>');
              });
            })(jQuery);

        </script>
    <?php   
    });
});

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

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