GF_Field_Image_Choice

Introduction

The GF_Field_Image_Choice class extends the GF_Field_Multiple_Choice class and handles image choice fields in Gravity Forms. This field type allows users to select from a list of image options rather than just text-based choices. The class determines how the image 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 image choice label visibility setting

$label_visibility = $field->imageChoiceLabelVisibility;

Settings

The following settings are available for the image choice 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).
image_choice_ui_show_label_settingControls whether labels for images are displayed.
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_Multiple_Choice 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.
checkbox_choiceUsed for checkbox functionality in image choices.
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.
imageChoiceLabelVisibilityControls whether labels are shown or hidden for image choices. Can be ‘show’ or ‘hide’.
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.

Hooks

Usage Example

// Get the field

$field = GFFormsModel::get_field($form, 1);

// Get field properties

$choices = $field->choices;

$label_visibility = $field->imageChoiceLabelVisibility;

// Check if labels are visible

$are_labels_visible = ($label_visibility === 'show');

// Get image URL for a selected choice

$merge_tag_value = '{Field:1:img_url}';

Source Code

The source code is located in class-gf-field-image-choice.php in the Gravity Forms plugin directory.