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.

Query Submitted Forms from Custom Page

  1. Hey there,

    I've looked but can't seem to find the exact information. Can I query and list submitted forms from a custom page? I'm talking PHP here, not within a Page or a Post. I'd like to be able to list out entries specific to the user that's logged in.

    Posted 13 years ago on Friday September 30, 2011 | Permalink
  2. I've added a hidden field that is storing the current user's username...

    What would be the recommended query for pulling all entries and the data utilizing that username?

    Posted 13 years ago on Friday September 30, 2011 | Permalink
  3. So, in all your forms, you're keeping track of the logged in user's username, in a hidden field, and you want to query all forms for all entries submitted by a specific username? What part of the entry will you display on the user's custom page?

    I just did something similar for a site pulling all the usernames that have submitted a different form, using this built in Gravity Forms function and a shortcode I created:

    [php]
    RGFormsModel::get_leads

    There is also a

    [php]
    RGFormsModel::get_lead

    singular. The plural allows more options for sorting, which was useful for my function.

    I don't think this is well documented but I can help you with it if you share a few more details about what you're looking to do.

    • Will you look through every form on your site? Or just specific forms?
    • Does every form have the hidden username field?
    • If the hidden field is not the same ID in every form, you will need to have the form ID and the field ID for each form you want to check.
    • When you find a submission from a user, what part of the entry are you going to display?
    • You will need a way to control access to each user's page before showing them their entries (assuming you don't want everyone to see everyone else's entries.)
    Posted 13 years ago on Saturday October 1, 2011 | Permalink
  4. Chris,

    Thanks for taking at look at this. And I'm sorry about the subtle "double post" ... I totally forgot I posted this question here.

    Ultimately, I feel that clients should not be using the GF admin interface. There are too many options and I don't want to have to display a "you don't have permission or enough privileges on your own site to do what you want." Know what I mean?

    So instead, I've created a plugin with it's own interface, and I'd love to be able to display the GF data in my own way... make sense?

    Posted 13 years ago on Tuesday October 4, 2011 | Permalink
  5. Yes, it makes sense. What do you need help with first? Have you looked at the Developer Docs? They're very good. The hooks and filters you need are all documented there.

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

    Posted 13 years ago on Tuesday October 4, 2011 | Permalink
  6. Yes, I've looked through the Dev Docs... but it seems that most, if not all hooks are for creating entries. I don't have an issue using the forms created by GF. What I need is to be able to list out entries of a particular form, sort through them (WP_List_Table class), display them on custom pages.

    I don't know where to start... it's not that obvious.

    Posted 13 years ago on Tuesday October 4, 2011 | Permalink
  7. AndrewTraub
    Member

    Can the form entries be shown on a page or post using shortcodes or does the page/post have to be hacked with hooks?

    Andrew

    Posted 13 years ago on Tuesday November 1, 2011 | Permalink
  8. There are no shortcodes in Gravity Forms to display entries. You can use hooks and Gravity Forms functions to get at the data.

    Posted 13 years ago on Tuesday November 1, 2011 | Permalink
  9. AndrewTraub
    Member

    Thanks Chris,

    Is there a sample I can look at which shows how to display basic things like a name and email address?

    Andrew

    Posted 13 years ago on Wednesday November 2, 2011 | Permalink
  10. Hi Andrew. Here is some code I wrote for one application.
    http://pastebin.com/kHpaHQvi

    You can see the result of using the shortcode here:
    http://troop24riverside.com/upcoming-events/

    My use was easy to pull off because they use the same form for all events, and the name is always the same field. So, 1.3 and 1.6 in my example. If you want a generic shortcode, you might have to extend it to allow multiple parameters, like field IDs.

    Let me know if that gets you going in the right direction. There is probably an opportunity for a Gravity Forms Shortcode plugin, along the lines of Justin Tadlock's Template Tag Shortcodes.

    http://justintadlock.com/archives/2009/03/24/template-tag-shortcodes-wordpress-plugin

    Posted 13 years ago on Wednesday November 2, 2011 | Permalink
  11. AndrewTraub
    Member

    The code looks like it loops through all form entries - is there a simple way to show the entries that were just entered in by the visitor - i.e. if I get their name and address and I just want to show that back to them on the next page, is there sample code for that?

    Thanks,

    Andrew

    Posted 13 years ago on Wednesday November 2, 2011 | Permalink
  12. It does loop through all entries, since that's what I needed to do.

    You did not mention that you wanted to show all entries made by a certain visitor or user. But you can do that. If you return all the form entries, you can use a conditional to check for the existence of a specific username or name and address combination. Or, if you look at the get_leads function in forms_model.php, you will find all sorts of nifty parameters you can send to the function:

    [php]
    public static function get_leads($form_id, $sort_field_number=0, $sort_direction='DESC', $search='', $offset=0, $page_size=30, $star=null, $read=null, $is_numeric_sort = false, $start_date=null, $end_date=null, $status='active') {
    Posted 13 years ago on Thursday November 3, 2011 | Permalink
  13. AndrewTraub
    Member

    I'm a bit dense. I'm really letting a visitor fill in a form. Then, on another page, I want to show them what they entered to review it and either edit it again (on the same page or by going back to the prior page where the entries will be filled out) or clicking OK to advance. So how do I show the visitor who just completed a form what he just entered in on another page or post? I'm not seeing anything in the get_leads you showed above on how to filter by the visitor (maybe by session id or something).

    Andrew

    Posted 13 years ago on Thursday November 3, 2011 | Permalink
  14. Hi Andrew,

    You might consider using the gform_confirmation hook to show the user the information that they just submitted. You'll see that one of the available parameters of this hook is the $lead variable which contains all of the just-submitted information.

    As far as allowing the user to update this information... that would essentially require that you query the database with the adjusted values.

    Do you have an example of what you currently have setup we could see? Might be able to guide you better. :)

    Posted 13 years ago on Thursday November 3, 2011 | Permalink
  15. AndrewTraub
    Member

    I'm trying to duplicate the functionality of this url:

    http://www.registeredagentintexas.com/signup.html

    After you enter the values, you are taken to a contract page. You can modify the values in the sidebar or pay online. Once the payment is made, the values are used again to send out a PDF containing them.

    Andrew

    Posted 13 years ago on Friday November 4, 2011 | Permalink
  16. Hi Andrew,

    Thanks for the link. That cleared things up significantly. :)

    Not sure if you have any dev experience; however, you'll likely need a little to get this up and running. Here is a top level view of how this would work. First off, you'll need two forms. The first form would be a multi-page form. The first page would have the user info you are collecting. The second page would have whatever content you want to display to the user before they confirm the submission.

    The second form would appear in the sidebar of the page containing the first form. You can use the gform_pre_render hook and check which page of the form is being displayed. If it is the second page, you can allow the "edit" form to display by default. If not, you can hide it.

    To prepopulate the values for the second form, you can pull them from the $_POST and use the gform_field_value hook to populate those retrieved values for each field based on it's dynamic population parameter (advanced tab of each field).

    That's quite a bit if you're just diving into Gravity Forms; however, I think you'll find that most of the hooks are well documented and if you have any specific questions on this while you're working on it, we'd be happy to help. :)

    Posted 13 years ago on Friday November 4, 2011 | Permalink