The gform_email filter in Gravity Forms PHP is used to modify the “Email” label when creating an email field.
Usage
A generic example that applies to all forms:
add_filter('gform_email', 'change_email', 10, 2);
To apply the filter to a specific form, use the form ID. In this example, form ID 5:
add_filter('gform_email_5', 'change_email', 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_email
Examples
Change the default email label
Change the default email label to “Your Email”:
add_filter('gform_email', 'change_email', 10, 2); function change_email($label, $form_id) { return 'Your Email'; }
Change the email label for a specific form
Change the email label to “Work Email” for form ID 5:
add_filter('gform_email_5', 'change_work_email', 10, 2); function change_work_email($label, $form_id) { return 'Work Email'; }
Change the email label based on form ID
Change the email label to “Personal Email” for form ID 3 and “Business Email” for form ID 4:
add_filter('gform_email', 'change_email_based_on_form', 10, 2); function change_email_based_on_form($label, $form_id) { if ($form_id == 3) { return 'Personal Email'; } elseif ($form_id == 4) { return 'Business Email'; } return $label; }
Change the email label to an HTML formatted string
Change the email label to an HTML formatted string, including a required asterisk:
add_filter('gform_email', 'change_email_html', 10, 2); function change_email_html($label, $form_id) { return 'Email Address <span class="required">*</span>'; }
Change the email label with a custom translation function
Use a custom translation function to change the email label:
add_filter('gform_email', 'translate_email_label', 10, 2); function translate_email_label($label, $form_id) { return my_custom_translation_function($label); }
Note: Replace my_custom_translation_function
with your actual translation function.