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.

Loading gravity form via ajax

  1. Hey guys,

    I've searched here and across google to find the answer, and I've found a few people with the problem, however I haven't seen full resolution.

    We have a site that pulls in content templates via ajax and loads them onto the page. Some of those pages have gravity forms in their templates. While the HTML structure is being pulled in, the forms look a little bit messed up. When you hit the page with the gravity forms without ajax, the form works fine. I've confirmed that I'm grabbing everything with the ajax ( entire HTML structure, and embedded javascript that is printed out with the gravity_forms() function.

    Here are a couple of images that might help clarify:
    What form looks like pulled in via ajax: http://cl.ly/image/1l3E1U1Q3T2e
    What form looks like when viewed normally: http://cl.ly/image/0q051z070L1J

    When viewed normally, the form works perfectly, and submits via ajax perfectly. My guess is that there is some javascript function that needs to fire, that isn't running when it's pulled in via ajax.

    Thanks in advance for your help!

    Posted 12 years ago on Saturday November 17, 2012 | Permalink
  2. I think you will need to enqueue your own scripts and styles when loading your form this way. Please see the gravity_form_enqueue_scripts function:
    http://www.gravityhelp.com/documentation/page/Gravity_form_enqueue_scripts

    Posted 12 years ago on Saturday November 17, 2012 | Permalink
  3. That doesn't seem to work. It seems that the javascript needs to be loaded and fired just after the .load(), however enqueuing scripts only loads scripts in the header, therefore, it wouldn't know that a new form has been loaded onto the page. Any other thoughts?

    Posted 12 years ago on Tuesday November 20, 2012 | Permalink
  4. I did a little bit more digging, and I found out that by sending the AJAX request to the wordpress admin-ajax.php file, the form spits out like it is in the backend of the admin page. There is a constant defined called IS_ADMIN, that is referenced throughout the code. However, by hitting admin-ajax.php, IS_ADMIN returns to be true.

    Once I turn IS_ADMIN to false before the gravityforms.php file loads, the form loads in fine, however this isn't really a proper fix, as it still does not even properly submit the form via ajax.

    Do you guys have a preferred method to pulling in a form through ajax?

    Posted 12 years ago on Tuesday November 20, 2012 | Permalink
  5. I will ask the developers for their input.

    Posted 12 years ago on Tuesday November 20, 2012 | Permalink
  6. This is actually a limitation we have. We have had a few users with this issue and this is something we will eventually get around, but currently you can't load the form via the admin-ajax.php file. The only recommendation I have at this point is to implement your own ajax page and load the form via that page instead of admin-ajax.php.

    Posted 12 years ago on Wednesday November 21, 2012 | Permalink
  7. I have the same problem when loading posts with AJAX and templates trying to render gravity forms this way.

    Posted 12 years ago on Tuesday December 11, 2012 | Permalink
  8. @Tritech, do you need assistance with something or were you just sharing your own experience?

    Posted 12 years ago on Thursday December 13, 2012 | Permalink
  9. I've got one question:
    How do I set the IS_ADMIN constant to false?

    I have no expierence in setting constants...

    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  10. You can set a constant like this:

    define('IS_ADMIN', FALSE);
    Posted 11 years ago on Tuesday January 15, 2013 | Permalink
  11. Hi Cris,

    Thanks for your response. I tried setting the constant; but it doesn't work for me. I also tried
    cons IS_ADMIN = false; (or 0) but that also didn't work for me.

    I did soms reading; and I saw that it isn't possible to change a constant (hence the name Constant). So maybe there is a other way? Or do I need to set the constant somewhere else?

    Edit:
    Some additional information. Right now i'm trying to (re)set the constant before including the gravity form. I'm including the form via do_shortcode() and gravity_form(); Makes no diffrence.

    When I echo the "IS_ADMIN" constant, I returns a TRUE;

    Posted 11 years ago on Wednesday January 16, 2013 | Permalink
  12. As Alex said previously, this is something we are addressing in development so that this is possible in the future.

    Posted 11 years ago on Wednesday January 16, 2013 | Permalink
  13. Hi Chris,

    That would be great. Any idea when this issue will be solved? Because I'm using this on one of my sites and my client would like to see it working ;)

    Thanks for all your work!

    Posted 11 years ago on Tuesday January 22, 2013 | Permalink
  14. We don't have a timeframe for addressing that. We're wrapping up development of the 1.7 beta version now.

    Posted 11 years ago on Tuesday January 29, 2013 | Permalink
  15. @Chris Hajer > I have the same problem as bmonzon explained.

    Loading several posts (a loop) with AJAX and the posts with GF will not load/render the GF forms correctly.

    Are you guys still working on solving this bug or can you point me in any direction to how this can be solved?

    Posted 11 years ago on Monday February 11, 2013 | Permalink
  16. As Alex stated here http://www.gravityhelp.com/forums/topic/loading-gravity-form-via-ajax#post-94115 it is a limitation currently and is something we are going to address.

    Posted 11 years ago on Tuesday February 12, 2013 | Permalink
  17. Is there any news about this issue?
    Would be great :)

    Posted 11 years ago on Monday March 25, 2013 | Permalink
  18. There is no new news Derk.

    Posted 11 years ago on Monday March 25, 2013 | Permalink
  19. I would just like to add my voice to this. We would definitely like this issue resolved.

    Posted 11 years ago on Wednesday June 19, 2013 | Permalink
  20. David Peralty

    We don't see this as an issue, but instead a limitation. There hasn't been any new news regarding this, and while it is still on our list of developments, it is not actively being worked on at this time. Will it be dealt with in our next development cycle after the current set of releases are out? I can't speak to that as our development is partially influenced by external factors. Keep reading our blog for updates.

    Posted 11 years ago on Wednesday June 19, 2013 | Permalink