【问题标题】:PHP hook (wpcf7_mail_sent) and JS event (wpcf7mailsent) don’t work togetherPHP 钩子 (wpcf7_mail_sent) 和 JS 事件 (wpcf7mailsent) 不能一起工作
【发布时间】:2018-02-20 07:26:12
【问题描述】:

我正在尝试做某事,但比预期的要困难一些,我需要帮助。

我想用我的表单做两件简单的事情: 1 – 在数据库中写入数据 2 – 在感谢页面上重定向

function createUser($contact_data) 
{
    var_dump($contact_data->posted_data);

    $phone = $_POST['your-phone'];
    $callname = $_POST['your-name'];
    $pwd = $_POST['pwd'];

    addUserInDB($phone,$pwd,$callname); /* this part works fine */

    header('Location: https://www.google.com'); /* A - not working */

    ?>
        <script type="text/javascript">
            window.location.href = "https://google.com/"; /* B - not working */

            document.addEventListener( 'wpcf7submit', function( event ) {
            window.location.href = "https://google.com/"; /* C - not working */
            }, false );

            document.addEventListener( 'wpcf7mailsent', function( event ) {
            window.location.href = "https://google.com/"; /* D - not working */
            }, false );
        </script>
    <?php
}
add_action("wpcf7_mail_sent", "createUser", 10, 1);

我尝试了四种不同的方法,现在我不知道该怎么做了……

【问题讨论】:

    标签: javascript php wordpress contact-form-7


    【解决方案1】:

    【讨论】:

    • 谢谢,但它也不起作用,所以我决定使用我自己的表单而不使用联系表 7。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    相关资源
    最近更新 更多