【问题标题】:Gravity Forms Hook - Insert jQuery (not defined error)Gravity Forms Hook - 插入 jQuery(未定义错误)
【发布时间】:2015-09-01 18:35:55
【问题描述】:

我试图将一些 jQuery 插入重力表单挂钩 (gform_post_paging) 以禁用多页表单上的上一个按钮。我收到一个 jQuery 未定义错误。我确定正在调用 jQuery,所以不确定发生了什么。如果这很重要,多页表单正在使用 ajax。

我的代码:

add_action( 'gform_post_paging_4', 'alert_user', 10, 3 );
function alert_user( $form, $source_page_number, $current_page_number ) {
        if ( $current_page_number == 2 ) {

            $to = $_POST['input_3'];
            $subject = ot_get_option( 'consultant_verification_email_subject' );
            $headers = array('Content-Type: text/html; charset=UTF-8');
            // get the email content from option tree.  We are setting a static value for the code.
            // if this code needs to change, it should be updated in gravity forms for now
            // @todo: we could randomize this value if we want then check the value using jquery
            $body = ot_get_option( 'consultant_verification_email' );

            wp_mail( $to, $subject, $body, $headers );

            ?>

            <script type="text/javascript">
                alert( 'An email was sent to <?php echo $to; ?> with your verification code.  Please enter this code to continue.  Should you have failed to receive this email, please click the previous button, confirm your email, and click next again.  Should you continue to encounter difficulty, please contact us.' );
            </script>

            <?php
        } else if ( $current_page_number == 3 ) {
            // disable the previous button so user cant go through verification steps again
            ?>
            <script type="text/javascript">
                jQuery(".gform_previous_button").prop("disabled",true);
            </script>
            <?
        }
    }

【问题讨论】:

  • 你在加载之前调用 jquery。将脚本放入排队的 js 文件中 (google wp_enqueue_script)。
  • 如果我只希望脚本在加载某个页码时运行(参见上面代码中的条件语句)?
  • 相同的逻辑,但更新了一个普通的 js 函数,你可以在下面使用它。

标签: jquery wordpress gravity-forms-plugin


【解决方案1】:

可能同样易于使用 vanilla js:

    <script type="text/javascript">
        document.getElementsByClassName('gform_previous_button')[0].disabled = true;
    </script>

同样简单!

【讨论】:

    猜你喜欢
    • 2012-12-14
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 2018-05-31
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-26
    相关资源
    最近更新 更多