Skip to content

Instantly share code, notes, and snippets.

@RickeyMessick
Created November 3, 2015 21:11
Show Gist options
  • Save RickeyMessick/fc1849be8305d253c921 to your computer and use it in GitHub Desktop.
Save RickeyMessick/fc1849be8305d253c921 to your computer and use it in GitHub Desktop.
Gravity Forms get all fields function to use with gform_after_submission to display just filled out fields
function get_all_fields($entry, $form)
{
//only do this for a certain form (id 53 for example)
// if ($form["id"] == 17)
//{
foreach($form["fields"] as &$field)
{
//see if this is a multi-field, like name or address
if (is_array($field["inputs"]))
{
//loop through inputs
foreach($field["inputs"] as &$input)
{
$label = $input["label"];
//get value from entry object; change the id to a string
$value = $entry[strval($input["id"])];
if (!empty($value)) {
$output .= $label . ':' . $value . ' ';
}
//print_r($output);
}
}
else
{
$label = $field["label"];
//get value from entry object
$value = $entry[$field["id"]];
if (!empty($value)) {
$output .= $label . ':' . $value . ' ';
}
//print_r($output);
}
}
//print_r($output);
return $output;
// }
}
@samjco
Copy link

samjco commented May 9, 2022

What about

// Get the Form fields
$form_id = 1;
$form = RGFormsModel::get_form_meta($form_id);

// Run through the fields to grab an object of the desired field
$field = RGFormsModel::get_field( $form, $field_id );


echo $field->label      // Gets the label
echo $field->inputName  // Gets the name
echo $field->type       // Gets the type
echo $field->cssClass   // Gets the CSS Classes as a string

Or:

$form_id = 1;
$form = RGFormsModel::get_form_meta($form_id);
        $fields = array();

        if(is_array($form["fields"])){
            foreach($form["fields"] as $field){
                if(isset($field["inputs"]) && is_array($field["inputs"])){

                    foreach($field["inputs"] as $input)
                        $fields[] =  array($input["id"], GFCommon::get_label($field, $input["id"]));
                }
                else if(!rgar($field, 'displayOnly')){
                    $fields[] =  array($field["id"], GFCommon::get_label($field));
                }
            }
        }
        echo "<pre>";
       print_r($fields);
        echo "</pre>";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment