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:
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). |
image_choice_ui_show_label_setting | Controls whether labels for images are displayed. |
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_Multiple_Choice
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. |
checkbox_choice | Used for checkbox functionality in image choices. |
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. |
imageChoiceLabelVisibility | Controls whether labels are shown or hidden for image choices. Can be ‘show’ or ‘hide’. |
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. |
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.