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 submission.
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 page.
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:
//get the field
$field = GFFormsModel::get_field( $form, 1 );
//get 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_message_setting | Controls whether the “Custom Validation Message” 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 pages instead of the label. |
allowsPrepopulate | Determines if the field values can be dynamically populated. |
choiceAlignment | Controls the display orientation of choices. Can be ‘horizontal’ or ‘vertical’. |
choiceLimit | Controls whether the “Select All” option is available. Can be ‘unlimited’, ‘range’, 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. |
errorMessage | The custom error message 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. |
inputMask | Indicates if input masking is enabled for the field. |
inputMaskIsCustom | Indicates if a custom input mask is being used. |
inputMaskValue | The value used for input masking. |
inputName | The parameter name used when dynamically populating the field. |
inputType | The type of input 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 input allowed. |
noDuplicates | Indicates if duplicate values are not allowed. |
placeholder | The placeholder text for the field input. |
selectAllText | The text displayed for the “Select All” option. Defaults to “Select All” if not specified. |
size | The size of the field input. |
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
);
Hooks
- gform_field_choice_markup_pre_render
- gform_default_choice_alignment
- gform_field_choices_max_count_visible
Usage Example
// Get the field
$field = GFFormsModel::get_field($form, 1);
// Get 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 plugin directory.