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 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:

SettingDescription
admin_label_settingControls whether the “Admin Field Label” setting appears.
choice_min_max_settingControls minimum and maximum number of choices.
choices_settingControls whether the “Choices” setting displays, allowing creation of different options.
conditional_logic_field_settingControls whether the “Enable Conditional Logic” setting appears.
css_class_settingControls whether the “Custom CSS Class” setting displays.
description_settingControls whether the “Description” setting appears.
error_message_settingControls whether the “Custom Validation Message” setting appears.
horizontal_vertical_settingControls the alignment of choices (horizontal or vertical).
label_placement_settingControls the placement of the field label.
label_settingControls whether the “Field Label” setting appears.
prepopulate_field_settingControls whether the “Allow field to be populated dynamically” setting appears.
rules_settingControls whether the “Rules” settings section displays.
select_all_text_settingControls the text for the “Select All” option.
visibility_settingControls whether the “Visibility” setting displays.

Properties

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

PropertyDescription
adminLabelThe label to be used on admin pages instead of the label.
allowsPrepopulateDetermines if the field values can be dynamically populated.
choiceAlignmentControls the display orientation of choices. Can be ‘horizontal’ or ‘vertical’.
choiceLimitControls whether the “Select All” option is available. Can be ‘unlimited’, ‘range’, or a specific number.
choicesArray of choice options available for selection in the field. See Note.
cssClassCustom CSS class to be added to the field.
descriptionThe field description that will be displayed on the form.
descriptionPlacementControls the placement of the field description.
errorMessageThe custom error message to be displayed if the field fails validation.
formIdThe ID of the form this field belongs to.
idThe unique identifier for this field instance.
inputMaskIndicates if input masking is enabled for the field.
inputMaskIsCustomIndicates if a custom input mask is being used.
inputMaskValueThe value used for input masking.
inputNameThe parameter name used when dynamically populating the field.
inputTypeThe type of input used by the field.
isRequiredIndicates if the field is required. Default is false.
labelThe field label that will be displayed on the form.
labelPlacementControls the placement of the field label.
maxLengthThe maximum length of input allowed.
noDuplicatesIndicates if duplicate values are not allowed.
placeholderThe placeholder text for the field input.
selectAllTextThe text displayed for the “Select All” option. Defaults to “Select All” if not specified.
sizeThe size of the field input.
subLabelPlacementControls the placement of sub-labels.
typeThe field type identifier, set to ‘multi_choice’ for this field type.
visibilityControls 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

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.