Using Gravity Forms ‘gform_card_name’ PHP action

The gform_card_name filter allows you to modify the “Cardholder Name” label when creating the credit card field in Gravity Forms.

Usage

add_filter('gform_card_name', 'change_name', 10, 2);

function change_name($label, $form_id) {
    // your custom code here
    return $label;
}

Parameters

  • $label (string): The label to be filtered.
  • $form_id (integer): The current form’s ID.

More information

See Gravity Forms Docs: gform_card_name

Examples

Change Cardholder Name label

This example changes the default “Cardholder Name” label to “Name on Card”:

add_filter('gform_card_name', 'change_name', 10, 2);

function change_name($label, $form_id) {
    return "Name on Card";
}

Change label based on form ID

This example changes the label only for form ID 5:

add_filter('gform_card_name', 'change_name_for_form_5', 10, 2);

function change_name_for_form_5($label, $form_id) {
    if ($form_id == 5) {
        return "Name on Card (Form 5)";
    }
    return $label;
}

Add a prefix to the label

This example adds a prefix “Your ” to the default label:

add_filter('gform_card_name', 'add_prefix_to_label', 10, 2);

function add_prefix_to_label($label, $form_id) {
    return "Your " . $label;
}

Change label to uppercase

This example changes the default label to uppercase:

add_filter('gform_card_name', 'uppercase_label', 10, 2);

function uppercase_label($label, $form_id) {
    return strtoupper($label);
}

Append a custom message to the label

This example appends a custom message to the default label:

add_filter('gform_card_name', 'append_custom_message', 10, 2);

function append_custom_message($label, $form_id) {
    return $label . " (please enter exactly as shown on card)";
}