Js error in gravitational forms

We host Wordpress sites on wpengine. On this one site we use gravitational forms, but for some reason they stopped working. All we get is 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 fine. Has anyone encountered this problem? Has anyone understood why this is happening?

+11
source share
6 answers

The most common cause of this problem is the gravityforms.js file, which is included in the footer when it should be in the header.

If you embed a form using a function call, there is a second function call that you should use to include scripts and style sheets in header.php

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

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

+15
source

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

I used a bone theme that unregisters jQuery JS by default and adds my own using Google CDN, for example:

 // 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 is the default jquery script, and then it adds its own cdn-jquery script, which is good, besides the fact that Gravity form scripts are dependent on jquery and not cdn-jquery !

Since they cannot see the default jquery script, they do not load, and it may appear that they silently fail, simply throwing this JavaScript error, because the specified JavaScript loads without dependency checking.

In any case, I fixed this by renaming the bone registration script in jquery , maybe this is not the best way to fix it, but it works.

In addition, commenting out both code snippets will also fix this (and leave Wordpress JS installed by default).

Not sure if other topics do this, but it might be worth a search on your entire topic for wp_deregister_script('jquery'); or at least switch to the default theme to see if you have the same problem (exactly as I defined it).

+5
source

OK, I solved the problem. For some reason, the form_display.php file was not updated for some reason. So I just pushed this file to the server and it fixed it.

+2
source

You can also add the necessary GF scripts manually to header.php (no jQuery registration / unregistration steps are required!). 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> 
+1
source

I had this problem and in my case it was caused by CloudFlare RocketLoader ™. After I disabled it, the form loaded without any problems.

0
source

Move gravity form scripts to footer

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

Source: https://habr.com/ru/post/969645/


All Articles