Requiring a Cardholder Name

As some payment add-ons such as the Authorize.Net add-on do not require the cardholder name to be validated, it is not typically required within the credit card field. This snippet will allow you to require the cardholder’s name.

add_filter( 'gform_field_validation', function ( $result, $value, $form, $field ) {
	if ( $field->type == 'creditcard' && $result['is_valid'] && rgempty( $field->id . '.5', $value ) ) {
		$result['is_valid'] = false;
		$result['message']  = 'Please enter the cardholder first and last name.';
	}

	return $result;
}, 10, 4 );