The gform_address_state filter is executed when creating the address state field and can be used to modify the “State” label in Gravity Forms.
Usage
To apply the filter to all forms:
add_filter('gform_address_state', 'change_address_state', 10, 2);
To apply the filter to a specific form (for example, form id 5):
add_filter('gform_address_state_5', 'change_address_state', 10, 2);
Parameters
- $label (string) – The label to be filtered.
- $form_id (integer) – The current form’s id.
More information
See Gravity Forms Docs: gform_address_state
Examples
Change the default address state label
This example changes the default address state label to “Address State”:
add_filter('gform_address_state', 'change_address_state', 10, 2);
function change_address_state($label, $form_id) {
// Custom label for the address state field
return "Address State";
}
Change the address state label for a specific form
This example changes the address state label to “Province” for a specific form with form ID 3:
add_filter('gform_address_state_3', 'change_address_state_province', 10, 2);
function change_address_state_province($label, $form_id) {
// Custom label for the address state field
return "Province";
}
Change the address state label based on form ID
This example changes the address state label based on the form ID:
add_filter('gform_address_state', 'change_address_state_based_on_form', 10, 2);
function change_address_state_based_on_form($label, $form_id) {
// Different labels for different forms
if ($form_id == 1) {
return "State/Province";
} else if ($form_id == 2) {
return "Region";
}
// Default label for other forms
return $label;
}
Change the address state label to a required field
This example changes the address state label and adds a required field indicator:
add_filter('gform_address_state', 'change_address_state_required', 10, 2);
function change_address_state_required($label, $form_id) {
// Custom label for the address state field and mark as required
return "Address State *";
}
Change the address state label for multiple forms
This example changes the address state label for multiple forms with form IDs 4 and 7:
add_filter('gform_address_state', 'change_address_state_multiple_forms', 10, 2);
function change_address_state_multiple_forms($label, $form_id) {
// Custom label for forms 4 and 7
if (in_array($form_id, [4, 7])) {
return "State/Territory";
}
// Default label for other forms
return $label;
}