Gravity Forms Hook - 插入jQuery(未定义错误)

时间:2015-09-01 18:35:56

标签: jquery wordpress gravity-forms-plugin

我试图将一些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>
            <?
        }
    }

1 个答案:

答案 0 :(得分:0)

可能就像使用香草js一样容易:

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

同样容易!