js error on gravity forms

微笑、不失礼 提交于 2019-12-08 15:29:10

问题


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?


回答1:


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/




回答2:


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).




回答3:


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.




回答4:


You can also add the GF`s necessary scripts manually to header.php (no actions with registering/deregistering jQuery needed!). Example:

<link rel='stylesheet' id='gforms_formsmain_css-css'  href='/wp-content/plugins/gravityforms/css/formsmain.min.css' type='text/css' media='all' />
<link rel='stylesheet' id='gforms_ready_class_css-css'  href='/wp-content/plugins/gravityforms/css/readyclass.min.css' type='text/css' media='all' />
<link rel='stylesheet' id='gforms_browsers_css-css'  href='/wp-content/plugins/gravityforms/css/browsers.min.css' type='text/css' media='all' />
<script type='text/javascript' src='/wp-content/plugins/gravityforms/js/jquery.json-1.3.js'></script>
<script type='text/javascript' src='/wp-content/plugins/gravityforms/js/gravityforms.min.js'></script>



回答5:


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.




回答6:


Move Gravity forms` scripts to footer

add_filter("gform_init_scripts_footer", "init_scripts");
function init_scripts() {
    return true;
}


来源:https://stackoverflow.com/questions/23786388/js-error-on-gravity-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!