2
votes

I am using the gravity form on my site. I am working on create the custom report for this I have need gravity form fields name and id based on specific form id.Please let me know how I can do it.

I am using the following function but it is showing all forms info based on it. it is looking very hard to parse it. Please let me know any function so I can get fields name easily.

  $forms = RGFormsModel::get_forms_by_id(13);
4

4 Answers

5
votes

try this

function get_all_form_fields($form_id){
        $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>";
        return $fields;
    }
2
votes

It's not that hard to parse:

$fields=array();
foreach ( $forms['fields'] as $field ) {
    $fields[]=array($field['id'] => $field['inputName']);
}

P.S. I'm assuming you use Gravity Forms < 1.7 as RGFormsModel::get_forms_by_id is a deprecated function since 1.7

2
votes
// Get the Form fields
$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 );

I use the above to get a specific field I want to filter the value of. The $field contains an object with all the properties you want.

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
1
votes

You are able to get the entered value/content of a field by using rgpost() and by referencing the id ($field->id).

// Check the entered value of every field
foreach( $form['fields'] as &$field ) {

  // Get the content for the specific field
  $fieldContent = rgpost( "input_".$field->id );

  // Check the content
  if ( $fieldContent == ... ){}

}