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.

Display Gravity Form table entry on front end

  1. flameboyuk
    Member

    Hi, does anyone have a snippet and details that will allow me to grab a specific Gravity Form entry from the database to display on the front end?

    Posted 13 years ago on Sunday July 4, 2010 | Permalink
  2. Would this plugin help?
    http://wordpress.org/extend/plugins/gravity-forms-addons/

    get_gf_leads seems to grab all leads for a specific form. I guess you'd need to loop through them all or access just the one you need, by entry id.

    Posted 13 years ago on Sunday July 4, 2010 | Permalink
  3. flameboyuk
    Member

    Thanks for the input Illinois, I've given that a try but unfortunately I can only seem to get the longer values working. Any ideas on the shorter ones whether it's through the plugin or if anyone knows another way? If you know any code that would get that working, I'd love to hear it.

    Posted 13 years ago on Sunday July 4, 2010 | Permalink
  4. By longer values you mean "get_gf_field_value_long($leadid, $fieldid)" works, but you cannot get any other values using the "get_gf_leads" function?

    Can you explain what you're trying to do, with a form number and a field name or number, and how you'd like to be able to display the information on the front end? I'm certain someone can come up with some code given more information from you.

    Posted 13 years ago on Sunday July 4, 2010 | Permalink
  5. flameboyuk
    Member

    Hi Illinois, That's right, I mean the "get_gf_field_value_long($leadid, $fieldid)". I can't seem to return any other results though.

    Here's what I'm trying to do...

    I'm trying to add certain entries from the database to a page which would contain results of certain fields they've inputted. I do not want to display all of their results and those that I do would be contained within other text. I do not want to use custom fields for this as I would like to be able to edit the entries later in the database rather than through page edit to keep track of any changes made and export the details.

    An example...

    We will contact you in (entry result) days to discuss further details.

    The entry result in this one would be from Form ID 13, lead ID 131, and field no. 7.

    I would ideally like to call the entry using lead ID so that I can reuse a template for the page and just replace the lead ID for each person while keeping the form ID and field no the same. Also, I can use php within my page using Exec-PHP so there's not problem there. I would just add the php to call the entry within the sentence.

    If you or anybody else could give me a snippet that would be great as I'm still quite new to PHP.

    Many thanks

    Hayden

    Posted 13 years ago on Tuesday July 6, 2010 | Permalink
  6. I was able to get the "Gravity Forms Add-ons" plugin working. The confusion might be because get_gf_field_value_long accepts a lead_id and a field_id, where get_gf_leads returns an array of all entries for a specific form. Then you need to loop through the array to get the output you want to display.

    I set up a little test site here:
    http://guitar.chrishajer.com/2010/07/06/suggest-a-restaurant/

    In a sidebar widget, I added some code to pull the entries for my form (this happens to be form 4) and then display just some of the fields. If you submit the form with some data, it will be added to that widget output. Eventually, the output would need to be limited to a certain number of entries (maybe sorted by date entered, DESC.)

    The data in that widget that is from the form entries is:

    $fame $lname "recommended"
    $restaurant "on" $submitted

    Here's the code that is in my Exec PHP widget:
    http://www.pastie.org/1033624

    In this line:
    $leads=get_gf_leads(4, 6.6, 'ASC');
    4 is the form ID
    6.6 is the last name field and the field I want to sort by (ASCending).

    Hopefully that will give you enough to go on to get it working. This is the first time I tried to get it working, but it seems pretty useful for displaying entries on the front end.

    For your specific application, since you know the lead ID, there will need to be some way to compare the lead ID in the entry to your known lead ID and display it when it matches. I don't see a way with this plugin to pass a lead ID to it and pull out fields from a specific entry. You could do the whole thing with SQL, but this plugin and Gravity Forms aim to avoid you having to do that, I think.

    Hope that helps. I had fun learning how to do it.

    Posted 13 years ago on Wednesday July 7, 2010 | Permalink
  7. Looks like the entry time stamp is GMT and I didn't account for that in my date calculation. But, you get the idea, I hope.

    Posted 13 years ago on Wednesday July 7, 2010 | Permalink
  8. flameboyuk
    Member

    Hi Illinois, that's great. Thank you so much for you time.
    I've managed to get data to display on the front end now but I still can't work out how to only retrieve data from a specific lead. As of the moment, it retrieves data from all leads on the specified form.

    I don't need the pages to be created automatically so as long as I can just copy paste the code into the page and then just change the lead ID manually to the one I want, that is fine. Is there any way to include a lead ID in the Function that you know of?

    Posted 13 years ago on Wednesday July 7, 2010 | Permalink
  9. Can you email me please? chrishajer [at] gmail.com

    Easier that way, and quicker too.

    Posted 13 years ago on Wednesday July 7, 2010 | Permalink
  10. I created a new page on my test site:
    http://guitar.chrishajer.com/review-page/

    Here is the code that is in the content of that Page (this is everything)
    http://pastie.org/1035434

    Will you be able to make something work from that?

    I have no idea if this is the "right" way to do it, but it worked for me. There is probably a way to stop looping after matching the ID and exit the loop, but I didn't think too hard about that. Right now, it loops through all the entries and only outputs something if there is a match on the id.

    Posted 13 years ago on Thursday July 8, 2010 | Permalink
  11. AxellOnline
    Member

    Is there a way to modify this to pull up only entries entered by the current user? I am trying to make a form that people fill in on a daily basis and the entries for the last week will show up on their profile. Any help will be greatly appreciated. Thanks.

    Posted 13 years ago on Friday August 13, 2010 | Permalink
  12. @AxellOnline I'm working on something like this right now, did you ever get something figured out?

    Here is what I have so far (I'm also using the Gravity Forms + Directory Capabilities plugin):
    I have a hidden field on each form that captures the logged in user's username then I do something like this:

    global $current_user;
        get_currentuserinfo();
        $currently_logged_in_as = $current_user->user_login;
    $leads = get_gf_leads(3, 1, 'ASC');
    foreach($leads as $lead) {
    if ($lead[15] == $currently_logged_in_as) {
    ...display lead information ...
    }

    (note that $lead[15] just happens to be the hidden field that I was collecting the username in, it may be different for your form).

    I'm actually working on making this work so it's not dependent on the username, but the user's role.

    Hope this helps

    Posted 13 years ago on Tuesday December 14, 2010 | Permalink