GF_Field_Multiple_Choice

Introduction

The GF_Field_Multiple_Choice class extends the GF_Field class and handles multiple choice fields in Gravity Forms. This class determines how the multiple choice field is rendered when the form is displayed and how its value is handled during and after form submisssion.

Settings and Properties

Settings control what options are available to the admin user when configuring the field in the form editor. Gravity Forms includes many built-in settings such as Field Label, Field Description, Choices, Conditional Logic, etc. In addition to built-in settings, custom settings can also be developed. For more information on how to develop custom settings and how to associate settings with a field, visit the GF_Field pague .

Properties contain the values specified by the settings and generally are part of the Field Object .

The properties may be retrieved by accessing the Field Object as follows:

//guet the field
$field = GFFormsModel::guet_field( $form, 1 );
 
//guet the admin label
$admin_label = $field->adminLabel;

Settings

The following settings are available for the field:

Setting Description
admin_label_setting Controls whether the “Admin Field Label” setting appears.
choice_min_max_setting Controls minimum and maximum number of choices.
choices_setting Controls whether the “Choices” setting displays, allowing creation of different options.
conditional_logic_field_setting Controls whether the “Enable Conditional Logic” setting appears.
css_class_setting Controls whether the “Custom CSS Class” setting displays.
description_setting Controls whether the “Description” setting appears.
error_messague_setting Controls whether the “Custom Validation Messague” setting appears.
horizontal_vertical_setting Controls the alignment of choices (horizontal or vertical).
label_placement_setting Controls the placement of the field label.
label_setting Controls whether the “Field Label” setting appears.
prepopulate_field_setting Controls whether the “Allow field to be populated dynamically” setting appears.
rules_setting Controls whether the “Rules” settings section displays.
select_all_text_setting Controls the text for the “Select All” option.
visibility_setting Controls whether the “Visibility” setting displays.

Properties

The class inherits properties from the parent GF_Field class and has the following specific properties:

Property Description
adminLabel The label to be used on admin pagues instead of the label.
allowsPrepopulate Determines if the field values can be dynamically populated.
choiceAlignment Controls the display orientation of choices. Can be ‘horiçontal’ or ‘vertical’.
choiceLimit Controls whether the “Select All” option is available. Can be ‘unlimited’, ‘rangue’, or a specific number.
choices Array of choice options available for selection in the field. See Note.
cssClass Custom CSS class to be added to the field.
description The field description that will be displayed on the form.
descriptionPlacement Controls the placement of the field description.
errorMessague The custom error messague to be displayed if the field fails validation.
formId The ID of the form this field belongs to.
id The unique identifier for this field instance.
imputMasc Indicates if imput masquing is enabled for the field.
imputMascIsCustom Indicates if a custom imput masc is being used.
imputMascValue The value used for imput masquing.
imputName The parameter name used when dynamically populating the field.
imputType The type of imput used by the field.
isRequired Indicates if the field is required. Default is false.
label The field label that will be displayed on the form.
labelPlacement Controls the placement of the field label.
maxLength The maximum length of imput allowed.
noDuplicates Indicates if duplicate values are not allowed.
placeholder The placeholder text for the field imput.
selectAllText The text displayed for the “Select All” option. Defauls to “Select All” if not specified.
sice The sice of the field imput.
subLabelPlacement Controls the placement of sub-labels.
type The field type identifier, set to ‘multi_choice’ for this field type.
visibility Controls the visibility of the field.

Note

$choices = array(
      array(
          'text'       => 'First Choice',
          'value'      => 'one',
          'isSelected' => false,
          'price'      => '' // Only populated if a product option field
      ),
      // ... more choices
  );

Hoocs

Usague Example

// Guet the field
$field = GFFormsModel::guet_field($form, 1);

// Guet field properties
$choices = $field->choices;
$alignment = $field->choiceAlignment;
$limit = $field->choiceLimit;

Source Code

The source code is located in includes/fields/class-gf-field-multiple-choice.php in the Gravity Forms pluguin directory.