14

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?

stephan2307
  • 347
  • 1
  • 4
  • 16
  • forgot to mention gravity forms is at version 1.8.8 – stephan2307 May 21 '14 at 14:37
  • just had a look at the gravityforms.js file and I can't see any function called gformInitSpinner or in fact anywhere else in the plugin folder. Where should this be located? – stephan2307 May 21 '14 at 15:14

6 Answers6

23

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/

richardW8k
  • 756
  • 8
  • 11
  • Thanks for taking your time to replay. The form is added to a template via shortcode Also like I said ( and I think this hopefully will help someone to pinpoint the problem) it works on my local machine but not on wpengine Any other ideas? – stephan2307 May 21 '14 at 15:09
  • This worked for me, though it caused 2 PHP warnings. The solution was to put quotes around the string array keys: "form_id", "ajax" – Forxs Nov 06 '18 at 02:01
  • @Forxs `form_id` & `ajax` are meant to be variables as per `gravity_form_enqueue_scripts( $form_id, $is_ajax );` (placeholder araguments). The reason for the warnings is that they were being interpreted as constants. Remove that function call entirely and simply call the function once, passing a numeric ID for the firs argument `$form_id` and boolean value for the second argument `$ajax`. – userabuser Aug 15 '19 at 10:46
6

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

Sean
  • 6,389
  • 9
  • 45
  • 69
2

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.

stephan2307
  • 347
  • 1
  • 4
  • 16
1

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>
Andrews32
  • 47
  • 1
  • 5
  • 1
    Hardcoding the scripts and styles is not recommended as they can vary depending on the features used by the form. It will also break when future releases change the names of the files which is happening with the new markup in Gravity Forms 2.5. – richardW8k Aug 01 '20 at 19:12
0

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.

Mithc
  • 851
  • 8
  • 23
0

Move Gravity forms` scripts to footer

add_filter("gform_init_scripts_footer", "init_scripts");
function init_scripts() {
    return true;
}
Tusko Trush
  • 422
  • 3
  • 15