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.

Can't get AJAX to work for the life of me

  1. Nick
    Member

    Here's an example page: http://newscubamarketing.com/2011/just-do-it/ (although any post behaves the same)

    My two sidebar forms (the one email and the one in the modal Questions popover) are done via shortcodes. The form at the end of each post is done via PHP function call. None of them submit via AJAX.

    The modal widget code:

    <a class="lbp-inline-link-1" href="#"><img src="http://cdn.newscubamarketing.com/question.png" alt="Ask your SCUBA Marketing questions!" /></a>
    <div style="display: none;">
    <div id="lbp-inline-href-1" style="padding: 10px; background: #fff;">
            [gravityform id=11 title=true description=true ajax=true]
    </div>
    </div>

    The MailChimp widget code:
    [gravityform id=16 title=false description=true ajax=true]

    The end of post code is embedded in the Genesis Simple Hooks plugin, so it's a bit much to paste it all here.

    What am I doing wrong?

    PHP: 5.2.17
    MySQL: 5.1.52
    WordPress: 3.1.1
    Gravity Forms: 1.5.1

    Posted 13 years ago on Tuesday April 26, 2011 | Permalink
  2. The problem is the shortcode can only enqueue the necessary scripts when it's called from within the WordPress loop. So if you are calling it from a sidebar like you described, it can't enqueue the necessary CSS and scripts.

    You need to then manually enqueue the necessary CSS and Javascript if you are using the shortcode outside the scope of the WordPress loop or if you are using the function call to display a form.

    Documentation for the function call you use to enqueue the necessary CSS/Javascript can be found here:

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

    Since this form is in the sidebar of every page, the easiest thing to do is add this function call to the functions.php file of your theme.

    The function call is form specific, so if you have multiple forms that are persistent on every page you would need to call that function call multiple times. If you have some forms being called via a function call in a theme file, you can try placing that function call with the other in the theme file.

    WordPress only allows you to enqueue scripts in certain situations so it can't automatically enqueue the scripts. It's designed to work when called from the loop. Outside of the loop you have to manually enqueue the necessary scripts.

    Posted 13 years ago on Tuesday April 26, 2011 | Permalink
  3. Nick
    Member

    I added:

    gravity_form_enqueue_scripts(12, true);
    gravity_form_enqueue_scripts(11, true);
    gravity_form_enqueue_scripts(16, true);

    inside my functions.php file and now I get this:
    Fatal error: Class 'GFCommon' not found in /home/proscuba/public_html/wp-content/plugins/gravityforms/gravityforms.php on line 1201

    Any suggestions why the forms on these pages won't do AJAX since they are within the loop?
    http://newscubamarketing.com/contact/
    http://newscubamarketing.com/work-nick/

    (I've removed the code from functions.php so my site will load)

    Posted 13 years ago on Tuesday April 26, 2011 | Permalink
  4. It's hard to tell exactly whats going on without looking at your site setup and doing some testing. If you send us a WordPress admin login via our Contact Us form and reference this forum post we can take al ook and see what is going on. It could be a theme or plugin conflict.

    Posted 13 years ago on Wednesday April 27, 2011 | Permalink