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

0 人关注

我试图将一些jQuery插入一个gravity forms的钩子(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>
        } 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>
3 个评论
你是在jquery加载之前调用它。把脚本放到一个被排队的js文件中(google wp_enqueue_script)。
如果我只想让脚本在加载某个页码时运行(见上面代码中的条件语句),怎么办?
同样的逻辑,但我在下面更新了一个vanilla js函数,你可以直接使用。
jquery
wordpress
gravity-forms-plugin
Koleon
Koleon
发布于 2015-09-02
1 个回答
David
David
发布于 2015-09-04
0 人赞同

也许使用vanilla js来做这个也很容易。