简体   繁体   English

WordPress 网站尝试使用 CF7 插件防止多次表单提交

[英]Trying to prevent multiple form submissions with CF7 plugin in WordPress website

On a site guatemaladental.com I am trying to prevent multiple submissions in a Contact Form 7 contact form.在网站guatemaladental.com上,我试图防止在联系表格 7 联系表格中多次提交。 After the site loads, there is a popup after 8 seconds.网站加载后,8 秒后会有一个弹出窗口。 After clicking 'learn more', another popup loads with the simple contact form.单击“了解更多”后,另一个弹出窗口会加载简单的联系表格。 After clicking 'Send request' there is no apparent action, so some site visitors are clicking the button again.单击“发送请求”后没有明显的操作,因此一些站点访问者再次单击该按钮。 I am trying to disable the button and change the text while the form is submitting to prevent this.我试图在提交表单时禁用按钮并更改文本以防止这种情况发生。 I found this php code snippet that I have installed, but it is not working.我发现我已安装此 php 代码片段,但它无法正常工作。 I think that I am likely not targeting the element correctly.我认为我可能没有正确定位元素。 Any help is appreciated, thanks!任何帮助表示赞赏,谢谢!

    // Prevent Multi Submit on all WPCF7 forms
    add_action( 'wp_footer', 'prevent_cf7_multiple_emails' );

    function prevent_cf7_multiple_emails() {
    ?>

    <script type="text/javascript">
    var disableSubmit = false;
    jQuery('input.wpcf7-submit').click(function() {
        jQuery(':input[type="submit"]').attr('value',"Sending...");
        if (disableSubmit == true) {
            return false;
        }
        disableSubmit = true;
        return true;
    })
      
    var wpcf7Elm = document.querySelector( '.wpcf7' );
    wpcf7Elm.addEventListener( 'wpcf7_before_send_mail', function( event ) {
        jQuery(':input[type="submit"]').attr('value',"Sent");
        disableSubmit = false;
    }, false );

    wpcf7Elm.addEventListener( 'wpcf7invalid', function( event ) {
        jQuery(':input[type="submit"]').attr('value',"Submit")
        disableSubmit = false;
    }, false );
    </script>
    <?php
} ?>

I've tried using Chrome's dev options to find the ID and correctly target the button, but I have not been successful.我试过使用 Chrome 的开发选项来查找 ID 并正确定位按钮,但我没有成功。

jQuery('input.wpcf7-submit.my-submit-class').click(function() {

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

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