js error on gravity forms
Asked Answered
B

6

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?

Balsaminaceous answered 21/5, 2014 at 14:36 Comment(2)
forgot to mention gravity forms is at version 1.8.8Balsaminaceous
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?Balsaminaceous
C
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/

Crummy answered 21/5, 2014 at 15:0 Comment(3)
Thanks for taking your time to replay. The form is added to a template via shortcode <?php echo do_shortcode('[gravityform id=1 name=ContactUs title=false description=true ajax=true]'); ?> 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?Balsaminaceous
This worked for me, though it caused 2 PHP warnings. The solution was to put quotes around the string array keys: "form_id", "ajax"Stunsail
@Stunsail 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.Tyrannosaur
C
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).

Cahier answered 16/5, 2016 at 16:16 Comment(0)
B
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.

Balsaminaceous answered 22/5, 2014 at 8:40 Comment(1)
Hi, can you share the form_display.php that you pushed to the server.Aitchbone
S
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>
Spectrograph answered 29/7, 2019 at 0:15 Comment(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.Crummy
H
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.

Heraclea answered 22/1, 2017 at 23:25 Comment(0)
T
0

Move Gravity forms` scripts to footer

add_filter("gform_init_scripts_footer", "init_scripts");
function init_scripts() {
    return true;
}
Tsuda answered 7/9, 2019 at 8:25 Comment(1)
This will be enabled by default starting with Gravity Forms 2.5.Crummy

© 2022 - 2024 — McMap. All rights reserved.