Get gravity forms fields

user1734190 picture user1734190 · Aug 17, 2013 · Viewed 11.8k times · Source

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

Answer

Moshe ovadia picture Moshe ovadia · Dec 3, 2013

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;
    }