The gform_stripe_elements_classes filter allows you to modify the classes used with Stripe Elements to control the appearance of the Credit Card field in Gravity Forms.
Usage
add_filter('gform_stripe_elements_classes', 'your_function_name', 10, 2);
Parameters
- $cardClasses (array): An array of the current classes applied.
- $formId (int): The current form ID.
More information
See Gravity Forms Docs: gform_stripe_elements_classes
For more information about which classes may be applied, check out the classes reference in Stripe’s documentation.
Examples
Set custom Stripe classes
This example sets custom classes for the base, complete, and invalid states of the Stripe Credit Card field.
add_filter('gform_stripe_elements_classes', 'set_stripe_classes', 10, 2); function set_stripe_classes($cardClasses, $formId) { $cardClasses = array( 'base' => 'TestElement', 'complete' => 'TestComplete', 'invalid' => 'TestInvalid' ); return $cardClasses; }
Add a custom class to existing classes
This example adds a custom class to the existing classes for the base state of the Stripe Credit Card field.
add_filter('gform_stripe_elements_classes', 'add_custom_base_class', 10, 2); function add_custom_base_class($cardClasses, $formId) { $cardClasses['base'] .= ' CustomBaseClass'; return $cardClasses; }
Remove a class from existing classes
This example removes a specific class from the existing classes for the complete state of the Stripe Credit Card field.
add_filter('gform_stripe_elements_classes', 'remove_complete_class', 10, 2); function remove_complete_class($cardClasses, $formId) { $cardClasses['complete'] = str_replace('ClassToRemove', '', $cardClasses['complete']); return $cardClasses; }
Set classes conditionally based on form ID
This example sets different classes for the Stripe Credit Card field based on the form ID.
add_filter('gform_stripe_elements_classes', 'set_classes_based_on_form', 10, 2); function set_classes_based_on_form($cardClasses, $formId) { if ($formId == 1) { $cardClasses['base'] = 'FormOneBaseClass'; } elseif ($formId == 2) { $cardClasses['base'] = 'FormTwoBaseClass'; } return $cardClasses; }
Modify classes using an associative array
This example modifies the existing classes for the Stripe Credit Card field using an associative array.
add_filter('gform_stripe_elements_classes', 'modify_classes_with_array', 10, 2); function modify_classes_with_array($cardClasses, $formId) { $customClasses = array( 'base' => 'NewBaseClass', 'complete' => 'NewCompleteClass', 'invalid' => 'NewInvalidClass' ); $cardClasses = array_merge($cardClasses, $customClasses); return $cardClasses; }