Gravity Forms Ajax Not Working

AndrewD picture AndrewD · Mar 23, 2015 · Viewed 15.3k times · Source

Using Gravity Forms 1.8.1 , no other plugins activated. Tested also with latest build 1.9.2 Tested using Divi theme, as well as 2015 theme with same results. Tested in Chrome and Firefox with same results.

Added the following shortcode:

[gravityform id="1" name="test-form-1" ajax="true"]

The form submits, but always with non-ajax and refreshes the page. I can tell this by looking at the tab and viewing the 'Net' tabs in Chrome's developer tools and Firebug in Firefox. The XHR requests are empty, and the requests clear and post normally as they would if it was a non-ajax request.

This should work. I get no errors or conflicts when looking at Firebug's console tab. I found no one experiencing similar problems although not really sure how many gravity form users are paying attention to the behavior in firebug.

I'm sure I'm missing something obvious. Let me know what it is!


Relevant form code generated by Gravity Forms

<div id="gform_wrapper_1" class="gf_browser_gecko gform_wrapper">
   <a class="gform_anchor" name="gf_1" id="gf_1"></a>
   <form action="/sandbox/#gf_1" id="gform_1" target="gform_ajax_frame_1" enctype="multipart/form-data" method="post">
      <div class="gform_heading">
         <h3 class="gform_title">test-form-1</h3>
         <span class="gform_description"></span>
      </div>
      <div class="gform_body">
         <ul class="gform_fields top_label description_below" id="gform_fields_1">
            <li class="gfield               gfield_contains_required" id="field_1_1">
               <label for="input_1_1" class="gfield_label">Name<span class="gfield_required">*</span></label>
               <div class="ginput_container"><input type="text" tabindex="1" class="medium" value="Joe Smith" id="input_1_1" name="input_1"></div>
            </li>
         </ul>
      </div>
      <div class="gform_footer top_label"> <input type="submit" onclick="if(window[&quot;gf_submitting_1&quot;]){return false;}  if( !jQuery(&quot;#gform_1&quot;)[0].checkValidity || jQuery(&quot;#gform_1&quot;)[0].checkValidity()){window[&quot;gf_submitting_1&quot;]=true;} " tabindex="2" value="Submit" class="button gform_button" id="gform_submit_button_1"><input type="hidden" value="form_id=1&amp;title=1&amp;description=1&amp;tabindex=1" name="gform_ajax">
         <input type="hidden" value="1" name="is_submit_1" class="gform_hidden">
         <input type="hidden" value="1" name="gform_submit" class="gform_hidden">
         <input type="hidden" value="" name="gform_unique_id" class="gform_hidden">
         <input type="hidden" value="WyJhOjA6e30iLCJkZjhiZTNiZTg3NDNmMWNlNDNmNTk1N2M0NTY2ZTRiMSJd" name="state_1" class="gform_hidden">
         <input type="hidden" value="0" id="gform_target_page_number_1" name="gform_target_page_number_1" class="gform_hidden">
         <input type="hidden" value="1" id="gform_source_page_number_1" name="gform_source_page_number_1" class="gform_hidden">
         <input type="hidden" value="" name="gform_field_values">
      </div>
   </form>
</div>

Answer

Nate Beers picture Nate Beers · Feb 10, 2016

You should still keep your scripts in the footer for performance reasons. But you need to include this in the header.php right above your <?php wp_head(); ?>:

<?php gravity_form_enqueue_scripts(1,true) ?>

with 1 being the id of the form.