Using Gravity Forms ‘gform_email_background_color_data’ PHP action

The gform_email_background_color_data filter allows you to change the background color for the field data in the HTML email.

Usage

add_filter('gform_email_background_color_data', 'your_function_name', 10, 3);

Parameters

  • $color (string): The current background color. The default is #FFFFFF.
  • $field (Field Object): The current field.
  • $entry (Entry Object): The current entry.

More information

See Gravity Forms Docs: gform_email_background_color_data

Examples

Set background color to light blue

Change the background color for the field data in the HTML email to light blue (#CCCCFF).

add_filter('gform_email_background_color_data', 'set_email_data_color', 10, 3);

function set_email_data_color($color, $field, $entry){
    return "#CCCCFF";
}

Change background color based on field type

Change the background color for the field data in the HTML email based on the field type.

add_filter('gform_email_background_color_data', 'set_field_type_background_color', 10, 3);

function set_field_type_background_color($color, $field, $entry){
    if ($field->type == 'text') {
        return "#FFCCCC";
    } elseif ($field->type == 'email') {
        return "#CCFFCC";
    } else {
        return $color;
    }
}

Change background color for specific field ID

Change the background color for a specific field ID in the HTML email.

add_filter('gform_email_background_color_data', 'set_specific_field_background_color', 10, 3);

function set_specific_field_background_color($color, $field, $entry){
    if ($field->id == 5) {
        return "#FFCC99";
    } else {
        return $color;
    }
}

Change background color based on entry value

Change the background color for the field data in the HTML email based on the entry value.

add_filter('gform_email_background_color_data', 'set_entry_value_background_color', 10, 3);

function set_entry_value_background_color($color, $field, $entry){
    $entry_value = rgar($entry, $field->id);
    if ($entry_value == 'High Priority') {
        return "#FF9999";
    } else {
        return $color;
    }
}

Change background color for specific form

Change the background color for the field data in the HTML email for a specific form.

add_filter('gform_email_background_color_data', 'set_form_background_color', 10, 3);

function set_form_background_color($color, $field, $entry){
    if ($field->formId == 1) {
        return "#99CCFF";
    } else {
        return $color;
    }
}