2013-08-17 121 views
1

我在我的网站上使用重力形式。我正在为此创建自定义报告,我需要基于特定表单ID的重力表单字段名称和ID。请告诉我如何才能做到这一点。获取重力形式字段

我正在使用以下功能,但它显示基于它的所有表单信息。它看起来很难解析它。请让我知道任何功能,以便我可以轻松获取字段名称。

$forms = RGFormsModel::get_forms_by_id(13); 

回答

1

这并不难解析:

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

附:我假设你使用重力窗体< 1.7作为RGFormsModel :: get_forms_by_id是因为1.7

+0

注意:这不适用于Gravity Forms高级字段。 –

4

弃用的功能试试这个

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; 
    } 
0
// 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); 

我用上面得到一个特定的领域我想过滤的价值。 $字段包含一个包含所有所需属性的对象。

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