Field hooks
Deze inhoud is nog niet vertaald.
These hooks belong to the custom Gravity Forms fields that CampaignSuite Forms adds, and to the Select2 field type used in form and feed settings.
The Amount choice field also honours the standard Gravity Forms filters gform_field_choices and gform_field_choice_markup_pre_render, so existing code that uses them keeps working. Those are Gravity Forms hooks and are not described here.
Amount choice
Section titled “Amount choice”cs_forms_amount_choice_choices
Section titled “cs_forms_amount_choice_choices”Filter · includes/gravityforms/fields/class-gf-field-amount-choice.php
Filters the choices of an Amount choice field just before the field is rendered, so you can add, remove or reorder amounts per request. It also runs in the form editor and on the entry detail page, so check $is_admin if the change should only apply on the front end.
| Parameter | Type | Description |
|---|---|---|
$choices |
array[] |
The field’s choices, each with text, value, price, isSelected and, for the free amount, isOtherChoice. |
$form |
array |
The form being rendered. |
$value |
string |
The submitted, prepopulated or stored value. |
$entry |
array|null |
The entry, when an existing entry is shown. |
$field |
\CampaignSuite\Forms\Includes\GravityForms\Fields\GF_Field_Amount_Choice |
The field. |
$is_admin |
bool |
true in the form editor or on the entry detail page. |
Returns: array[] — the choices.
add_filter('cs_forms_amount_choice_choices', function ($choices, $form, $value, $entry, $field, $is_admin) { if ($is_admin || rgar($form, 'id') != 12) { return $choices; } return array_values(array_filter($choices, function ($choice) { return !empty($choice['isOtherChoice']) || (float) rgar($choice, 'price') <= 250; }));}, 10, 6);cs_forms_amount_choice_styles
Section titled “cs_forms_amount_choice_styles”Filter · includes/gravityforms/fields/class-gf-field-amount-choice.php
Filters the styles offered in the Appearance tab of the Amount choice field. A key is the CSS class added to the field wrapper and the value is the label in the editor. The plugin ships no CSS for these classes. They are there for your theme to style. The only default is gfield_amount_choice--horizontal-blocks (“Horizontal blocks”). Keys go through sanitize_html_class(), and entries that end up empty are dropped.
| Parameter | Type | Description |
|---|---|---|
$styles |
array<string, string> |
Labels keyed by CSS class. |
Returns: array<string, string> — the styles.
add_filter('cs_forms_amount_choice_styles', function ($styles) { $styles['gfield_amount_choice--cards'] = __('Cards', 'my-theme'); return $styles;});Address (NL)
Section titled “Address (NL)”cs_forms_address_nl_default_country
Section titled “cs_forms_address_nl_default_country”Filter · includes/gravityforms/fields/class-gf-field-address-nl.php
Filters the country value the Address (NL) field uses as its default, and as the value that decides when the Dutch postcode mask applies. The default is NL, the Gravity Forms country code for the Netherlands. Change it when your site uses a country list with other values, for example full names.
| Parameter | Type | Description |
|---|---|---|
$default_country |
string |
Default 'NL'. |
Returns: string — the country value.
add_filter('cs_forms_address_nl_default_country', function ($default_country) { return 'Netherlands';});Select2 settings field
Section titled “Select2 settings field”cs_forms_select2_required_options_for_search
Section titled “cs_forms_select2_required_options_for_search”Filter · includes/gravityforms/settings/fields/class-select2.php
Filters how many options a single-choice Select2 settings field needs before it shows its search box. The default is 10. Multi-select fields are not affected.
| Parameter | Type | Description |
|---|---|---|
$minimum |
int |
The minimum number of options. Default 10. |
$field |
\CampaignSuite\Forms\Includes\GravityForms\Settings\Fields\Select2 |
The settings field. |
Returns: int — the minimum number of options. Use 0 to always show the search box.
add_filter('cs_forms_select2_required_options_for_search', function ($minimum, $field) { return 5;}, 10, 2);