How do I show data from gravity forms in my template? [closed]

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).

Leave a Comment