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.

Detect if form has submitted

  1. g01010
    Member

    I thought this would be easy (and it probably is) but I haven't been able to figure it out.

    I'd like to hide page content from the user until they successfully submit a form on the same page. Doing this on different pages would be easy - I could just pass a variable from the page with the form on to the next page. But I can't work out how to do it on the same page.

    Any clues?

    Thanks.

    Posted 12 years ago on Monday March 5, 2012 | Permalink
  2. This isn't a built in feature so it's not something Gravity Forms itself is going to do for you. It is possible, but it would have to be implemented as a customization.

    I've actually never seen this particular question asked before so it's not something i've thought about so I don't have a solution off the top of my head.

    There are probably a variety of ways to handle this but ultimately it's going to depend on your specific use case. I can try and come up with a way to handle it but i'll need to know a little more information...

    Is the form you want them to fill out going to be the same for every page? Are you fine with this being cookie based so it uses browser cookies to know if it should show the content or not?

    Posted 12 years ago on Monday March 5, 2012 | Permalink
  3. g01010
    Member

    Thanks for your response...

    Is the form you want them to fill out going to be the same for every page?

    Yes.

    Are you fine with this being cookie based so it uses browser cookies to know if it should show the content or not?

    Yes.

    Posted 12 years ago on Monday March 5, 2012 | Permalink
  4. Here's what you could do...

    - Write custom PHP so that when the form is submitted, you set a cookie in the users browser containing the post/page id.

    - Write custom PHP in your theme template that is used to display your posts and/or pages so that posts that require a form submission check to see if the cookie exists, and if it does... if the post id for the post the user is viewing is in the cookie. If it is, show the post content. If it is not, show the form.

    This is a high level overview of what you would need to do. If this isn't something you can implement yourself based on your knowledge of WordPress then I could refer you to a list of WordPress developers who could assist you with this customization.

    Posted 12 years ago on Monday March 5, 2012 | Permalink
  5. g01010
    Member

    Thanks for this - I'm comfortable with everything you suggest... It's just the really fundamental thing of how to detect whether the form has been submitted when I don't know and can't specify the name for fields and/or the submit button.

    Normally I'd do this:

    if ( isset ( $_POST ['submit'] ) ) {
      //do stuff
    }

    But I can't do that without knowing the name of the Submit button... So all the rest of what you suggest makes perfect sense, I just can't get past the first and most basic step.

    EDIT:

    So I did a bit more playing around. Am I right that GF automatically adds a hidden field called gform_submit?

    I've used this to test whether the form has submitted:

    if ( isset ( $_POST ['gform_submit'] ) ) {
      //do stuff
    }

    Grateful if you could let me know if you see any problems with that.

    Posted 12 years ago on Tuesday March 6, 2012 | Permalink
  6. You will go about things a different way with Gravity Forms. You will need to use hooks to accomplish what you want to do.

    You would write custom PHP and that custom code would go in either your themes functions.php file, or you could create your own custom WordPress plugin to house that custom code and then activate that plugin.

    The hook you would use when the form is submitted to set the cookie is the gform_after_submission hook which is documented here:

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

    This is the hook you would use to implement your custom code to create the cookie.

    After the cookie exists you will then need to write the PHP in your theme template to check to see if the cookie exists or not and then respond accordingly.

    Posted 12 years ago on Tuesday March 6, 2012 | Permalink
  7. g01010
    Member

    Thanks for your help. I'll look into this.

    Posted 12 years ago on Wednesday March 7, 2012 | Permalink

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