PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

jQuery not working outsite content area

  1. Joshua.MacLeod
    Member

    I have a form here: http://persecutionproject.savethenuba.com/get-active/options/leader-or-influencer/

    That page is rendering a custom content type that I built. There's a field called Gravity Forms ID, and it simply takes the integter for the form. Then the template is running do_shortcode on a traditional graviry forms shortcode, dropping the proper ID in there.

    When I submit the form it does what it's supposed to on the back end (makes an entry, sends an email, etc.) but doesn't hide the form and show the thanks text via ajax.

    If I embed the form on a regular post it DOES do this properly.

    The form is outside the normal entry-content div, does that matter?

    Here's the line I'm using to print the form:

    print do_shortcode('[gravityform id="' . $meta_values['ecpt_gravityformsid'][0] . '" title="false" description="false" ajax="true"]');

    I'm not getting any JS errors in firebug or the Firefox JS console.

    Any ideas?

    Posted 12 years ago on Monday December 19, 2011 | Permalink
  2. The issue is how WordPress enqueue works. Gravity Forms is only able to automatically enqueue the necessary scripts when the shortcode is executed from a location that allows it.

    It will not automatically enqueue the necessary scripts and CSS when using the PHP function call or using do_shortcode on the Gravity Forms shortcode. This is a limitation of how WordPress enqueue works, it can only execute at certain points in the WordPress page execution. If the header has already been written when the code is executed it's too late to then add code to the header.

    In these situations you must use the Gravity Forms enqueue function in your themes functions.php to handle outputting the scripts and CSS in the header and footer where appropriate.

    This function call is documented here:

    http://www.gravityhelp.com/documentation/page/Gravity_form_enqueue_scripts

    Please note when using that in your themes functions.php file you'll want to wrap it in an if statement so that it only executes on a specific page, unless the form is going to be output on every page/post as in situations where it is part of the theme design itself (ex. in the footer, etc.).

    Posted 12 years ago on Monday December 19, 2011 | Permalink
  3. Joshua.MacLeod
    Member

    That got me closer, but it's not quite right yet. My header.php file now has this:

    <?php
        gravity_form_enqueue_scripts(3, true);
    ?>
    <?php wp_head() ?>

    Where 3 is the id of the form on that page, and I want to use JS. Now when I submit I see a little spinner appear (though antialiased and positioned oddly) but that's it.

    Posted 12 years ago on Monday December 19, 2011 | Permalink
  4. That isn't going to work. You need to put the enqueue function in your themes functions.php file, not above the wp_head() function.

    Posted 12 years ago on Monday December 19, 2011 | Permalink
  5. Joshua.MacLeod
    Member

    Yeah, I tried that originally and got the same result. The docs said to put it in header.php so I tried that too. I get the same result both ways.

    Posted 12 years ago on Tuesday December 20, 2011 | Permalink
  6. Joshua, can you post your functions.php please so we can see what you are trying based on Carl's previous reply? Thank you.

    Posted 12 years ago on Tuesday December 20, 2011 | Permalink
  7. Joshua.MacLeod
    Member

    During testing I simply have this:

    gravity_form_enqueue_scripts(3, true);

    Once I get it working I'll write in my if statements. 3 is the id of the form I'm working with. There is, of course, other stuff in functions.php that is unrelated to this. I assume you don't need to see that?

    Posted 12 years ago on Tuesday December 20, 2011 | Permalink
  8. We won't need the unrelated stuff, no. Just the stuff relevant to this form.

    Posted 12 years ago on Wednesday December 21, 2011 | Permalink
  9. Joshua.MacLeod
    Member

    That would be it then. :)

    Posted 12 years ago on Wednesday December 21, 2011 | Permalink
  10. Joshua.MacLeod
    Member

    Any hope for this one?

    Posted 12 years ago on Thursday December 22, 2011 | Permalink
  11. Joshua, can you send me an admin login for your site to chris@rocketgenius.com - I'm having a hard time figuring out what the issue is. In the email, reference this topic and also include a description of the problem you're having currently. Thanks

    Posted 12 years ago on Thursday December 22, 2011 | Permalink
  12. I noticed a couple things that are probably related. In the head, you are including an old, minimized version of jQuery, 1.2.3.

    http://persecutionproject.savethenuba.com/wp-content/themes/ppf/scripts/jquery-1.2.3.min.js

    That needs to go. The latest version of jQuery that is included with WordPress 3.3 and is compatible with Gravity Forms 1.6.2 is jQuery 1.7.1.

    http://persecutionproject.savethenuba.com/wp-includes/js/jquery/jquery.js?ver=1.7.1

    Two versions of jQuery being included will not work, especially when the older one is being called first. The hard-coded reference to the older one should be removed from the header.php.

    When you do that, everything that relies on jQuery will break though. jQuery needs to be properly included in the head section, not the footer, so it's available to all the scripts that rely on jQuery.

    So, remove the call to the older jQuery library, and properly enqueue the latest jQuery in the head and I think you will be good to go. Please do that and if it still does not work, let us know and we will continue troubleshooting.

    I made no changes to your site.

    Posted 12 years ago on Friday December 23, 2011 | Permalink
  13. Joshua.MacLeod
    Member

    That's brilliant, but fixing that didn't help. :(

    I took out the old call and installed "Use Google Libraries", which pulls in the latest from Google. I've verified that they're being pulled in properly.

    I get the same error on that Leadership page.

    As a test I also put that same form on a regular page, http://persecutionproject.savethenuba.com/what-we-do/

    It also fails in the same way. It's not utter failure, because the error checking works on required fields. It's simply not hiding the form and giving me thanks text on submit.

    Posted 12 years ago on Friday December 23, 2011 | Permalink
  14. Joshua.MacLeod
    Member

    NEW DIRECTION

    I took a stab at it with Contact Form 7 and it's working brilliantly. I really need this going asap since the due date was a week ago. :(

    I really appreciate your help and will still recommend and use GF on other site.

    Posted 12 years ago on Saturday December 24, 2011 | Permalink