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.

Form not displaying when using Conditional Logic (jQuery conflict)

  1. Hi Carl, Kevin and Co.

    I'm having a problem similar to the one that Armin was having - found on this thread: http://www.gravityhelp.com/forums/topic/another-conditional-logic-problem - and I'm hoping you guys could help out?

    Things you'll need to know:

    • Problem page: http://redalert.iceafrica.org/
      • This is the homepage for the site (though just a development URL right now)
      • There should be a form visible under the h2 heading - Request a quotation
      • I placed the content and called the form for this section into a content block (custom post widget) which sits in turn in a custom sidebar
      • You'll see, by viewing the page source, that Gravity Forms conditional logic script simply doesn't load (/wp-content/plugins/gravityforms/js/conditional_logic)
    • Page where problem doesn't exist: http://redalert.iceafrica.org/test-form/
      • This is a simple page, and the page content calls the form
      • You'll see, by viewing the page source, that Gravity Forms conditional logic does load...
      • ...and so the form works

    Things I have already tried to fix the problem:

    • I moved the wp-head around as Armin indicated this helped his problems. - No luck.
    • I tried loading jquery manually rather than loading via functions.php - that's clearly not the problem.
    • I tried removing my own two lots of jquery calls (jquery.nivo.slider.pack.js and jquery-calls.js) from my header.php - that makes no difference either.
      • These two files aren't loaded in the test-form page
    • To make triply sure it wasn't these two scripts, I placed all my jQuery functions in no-conflict mode using (jQuery.noConflict) and $j as my jquery shortcut. Still, no dice.
    • Then, lastly, I added another test page, similar to the first test page (which works). But this time, in the right-hand-side sidebar I added the problem widget content...
      • ...and you'll see that even though the form is available in the page content, AND the conditional logic js is loaded, the form in the sidebar will not load.

    I've got a feeling the problem comes in the the fact that the form is loaded into the custom post widget. Though this works when conditional logic is not called. And even though the script is called on the another-test-form page, the form doesn't load in the widget.

    I realise this is long-winded, but I thought I'd be thorough before posting.

    Let me know what you'd need in order to help me?

    Thank you in advance for any help and/or suggestions.

    Cheers
    Jon

    Posted 12 years ago on Wednesday May 25, 2011 | Permalink
  2. The form works fine on the one page because you are using the shortcode from page content and it can automatically enqueue the necessary CSS scripts when utilized like this.

    The form is not working fine on your homepage because of how you are calling it. Gravity Forms can't always enqueue the necessary scripts and CSS automatically. WordPress only allows this to happen when the shortcode is executed from a standard WordPress loop.

    If you aren't using a standard WordPress loop or are using the Gravity Forms function call directly in your theme, you have to manually enqueue the necessary scripts due to how WordPress executes code.

    You need to enqueue the scripts using the gravity_form_enqueue_scripts function which is documented here:

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

    You can try adding this to your homepage template file, although ideally it would reside in your themes functions.php file with code that only executes the function if it is your homepage since it's only needed on your homepage like so:

    <?php
    if ( is_home() ) {
        gravity_form_enqueue_scripts(1, true);
    }
    ?>

    The 1 in the function call needs to be replaced with your form id and the true can be true or false depending on if the form is configured to display using AJAX or not.

    Posted 12 years ago on Wednesday May 25, 2011 | Permalink
  3. Hi Carl

    Thanks for the prompt reply. What you're saying seems to make sense.

    Being new to Gravity Forms, I never realised that one was able to call the form from within a wordpress template file. I'd imagine that this would be the easiest way to go (and it would reduce a bit of weight by not having to register the extra sidebars, etc)?

    If I went this route, I'd imagine I'd still need to enqueue the scripts??

    Cheers
    Jon

    Posted 12 years ago on Wednesday May 25, 2011 | Permalink
  4. Yes, if you use the function call to display a form you need to enqueue the scripts using the enqueue function. The function call can't do it because enqueue can only occur at certain points in the WordPress execution. The functions.php file is one of those places where it can enqueue scripts. You can use an IF statement around your enqueue function call so it only occurs under certain circumstances, such as on a specific page.

    Posted 12 years ago on Wednesday May 25, 2011 | Permalink
  5. Hi Carl

    Perfect. I'll give it a whirl tomorrow when I'm back in the studio.

    Thanks for the great support.

    Posted 12 years ago on Wednesday May 25, 2011 | Permalink
  6. Hi

    I've tried both is_home and is_front_page as my conditional statements in functions.php, but these don't seem to work...

    Only this seems to work:
    gravity_form_enqueue_scripts(1, true);

    The statement is sitting in a larger, single <?php ?> along with other functions - if that helps...

    Posted 12 years ago on Wednesday May 25, 2011 | Permalink
  7. If it's working without the conditional statement thats good, you just need to determine what conditional you need to implement so you can implement it in such a way that it only happens when it is that specific page. If you use a page for your Homepage, then use is_singular and pass the page id.

    Posted 12 years ago on Wednesday May 25, 2011 | Permalink
  8. All sorted. Thanks for the help.

    If it helps anyone else, I wrapped the conditional statement in my own function in functions.php, like so:

    // enqueue gravity form script on homepage
    function queue_my_form_scripts() {
    	if (is_front_page()) {
    		gravity_form_enqueue_scripts(1, true);
    	}
    }
    add_action('get_header', 'queue_my_form_scripts');
    Posted 12 years ago on Thursday May 26, 2011 | Permalink

This topic has been resolved and has been closed to new replies.