Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Preface

I've installed gravity forms, created a form and users are submitting data to my site. What I want to do is show the data users are submitting to my site on one of my pages.

I know there's the Gravity Forms Directory plugin. But this gives only a fixed data presentation.

Question

Is there anything in gravity forms that can do something like this? (pseudo code):

<?php gforms_get_field( $form_id, $entry_id, 'user_name_field' ); ?>
share|improve this question

closed as off-topic by Johannes Pille, birgire, ialocin, mrwweb, Pieter Goosen Aug 31 at 3:31

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Your question should be specific to WordPress. Generic PHP/JS/HTML/CSS questions might be better asked at Stack Overflow or another appropriate site of the Stack Exchange network. Third party plugins and themes are off topic." – Johannes Pille, birgire, ialocin, mrwweb, Pieter Goosen
If this question can be reworded to fit the rules in the help center, please edit the question.

    
1  
@GhostToast Believe me I combed the docs completely and there isn't any information on how to achieve this. –  hitautodestruct Jan 24 '13 at 11:48
    
Note from the future: here's a plugin that is explicitly for displaying Gravity Forms data on the front-end: gravityview.co –  Dalton Aug 5 at 22:11

3 Answers 3

up vote 13 down vote accepted

You can look at the docs, but you'll probably end up reading the real documentation: the source code.

If you do, you'll find that:

  • GFFormsModel::get_leads($form_id) returns a list of entries for a form (maybe you know that one already), where each item in the array is itself an array, an "Entry object"
  • GFFormsModel::get_form_meta($form_id) returns a list of field meta elements (i.e. describes name, type, rules etc.) in the form, where each item in the array is a "Field object"

Once you have an Entry object, you can access the fields as elements, by field number. If you need to find a field by name or type, you need to iterate over the list of fields in the form to get a match, and then access the entry's field by field ID.

NB: determining a field's type is best done by passing the field's meta element to GFFormsModel::get_input_type($field)

Edit: note also that only the first 200 characters of each field are returned in the Entry object. If you have fields that store more information, you'll need to ask for it, e.g. by calling GFFormsModel::get_field_value_long($lead, $field_number, $form).

share|improve this answer
1  
FYI, A Gravity Forms admin posted this snippet for a shortcode pastebin.com/kHpaHQvi as well. –  hitautodestruct Jan 29 '13 at 9:27

Thanks to webaware for their answer.

Here's some copy/pasta for anyone looking for a quick start. This takes an entry ID and retrieves the lead and form from that. In this case I'm using the URL to pass the value. e.g. somedomain.com?entry=123.

<?php 
    $lead_id = $_GET['entry'];
    $lead = RGFormsModel::get_lead( $lead_id ); 
    $form = GFFormsModel::get_form_meta( $lead['form_id'] ); 

    $values= array();

    foreach( $form['fields'] as $field ) {

        $values[$field['id']] = array(
            'id'    => $field['id'],
            'label' => $field['label'],
            'value' => $lead[ $field['id'] ],
        );
    }
?>
<pre><?php print_r($values); ?></pre>
share|improve this answer
    
You code is great but wont work for Advanced fields like the address or the first name/last name since they are using . to split their ID –  Tareck117 Sep 30 at 18:58

You could use a gform_after_submission hook to write everything you need to a custom post type, which might be easier to manipulate "out in the field", and will be safe from, say, someone deleting a single field and obliterating all the data associated with it.

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

Yoast has a pretty good writeup on writing to custom fields, without even using the hook. http://yoast.com/gravity-forms-custom-post-types/

Good luck!

share|improve this answer
    
Duplicating data like this seems a bit nasty. –  Felix Eve Sep 18 at 7:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.