js error on gravity forms

2019-06-16 00:53发布

We are hosting wordpress sites on wpengine. On this one site we are using gravity forms but for some reason it stopped working. All we get is a js error

Uncaught ReferenceError: gformInitSpinner is not defined (index):135
(anonymous function) (index):135
o jquery.min.js:2
p.fireWith jquery.min.js:2
e.extend.ready jquery.min.js:2
c.addEventListener.B

Now if I set up the site on my local machine it works perfectly fine. Has anyone come across this problem? Anyone got any idea why this is happening?

4条回答
相关推荐>>
2楼-- · 2019-06-16 01:17

I just had this problem and, in my case, it was caused by CloudFlare RocketLoader™. After I disabled it, the form loaded with no problem.

查看更多
你好瞎i
3楼-- · 2019-06-16 01:28

The most common cause of this issue is the gravityforms.js file being included down in the footer when it should be up in the header.

If you are embedding the form using the function call there is a second function call you should use to include the scripts and stylesheets in the header.php

gravity_form_enqueue_scripts(form_id, ajax);
gravity_form_enqueue_scripts(4, true);

https://docs.gravityforms.com/gravity_form_enqueue_scripts/

查看更多
We Are One
4楼-- · 2019-06-16 01:35

OK I solved the problem. For some reason the file form_display.php was for some reason not up to date. So I simply pushed that one file to the server and this fixed it.

查看更多
看我几分像从前
5楼-- · 2019-06-16 01:42

I had exactly the same problem, and managed to track it down to some theme code.

I was using the bones theme, which de-registers the default jQuery JS and adds its own using the Google CDN, like:

// we don't need the Wordpress jquery as we are loading our own version
add_action('wp_enqueue_scripts', 'stnic_remove_jquery');
function stnic_remove_jquery(){
    if(!is_admin()) {
        wp_deregister_script('jquery');
    }
}


// loading modernizr and jquery, and reply script
function bones_scripts_and_styles() {
    if (!is_admin()) {
        wp_register_script( 'cdn-jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js', array(), '', false );
    }
}

As you can see, it deregister's the default jquery script, and then adds its own cdn-jquery script, which is fine, apart from the fact that the Gravity forms scripts have a dependency on jquery and not cdn-jquery!

Because they can't see the default jquery script, they don't load, and it would seem that they fail silently, simply emitting this JavaScript error because said JavaScript is loaded without checking dependencies.

In any case, I fixed it by re-naming the bones register script to jquery, might not be the best way to fix this, but it works.

Alternatively, commenting out both pieces of code would also fix this (and leave the default Wordpress JS in there).

Not sure if other themes do this, but might be worth doing a search all in your theme for wp_deregister_script('jquery'); or at least switching to the default theme to see if you experience the same problem (that's how I pinpointed this).

查看更多
登录 后发表回答