Skip to content

Instantly share code, notes, and snippets.

@spivurno
Last active April 10, 2022 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spivurno/66e0d36495b7c1ed9444d6e77ecf168e to your computer and use it in GitHub Desktop.
Save spivurno/66e0d36495b7c1ed9444d6e77ecf168e to your computer and use it in GitHub Desktop.
Gravity Perks // GP Copy Cat // Copy Credit Card Name to Name Field
<script>
/**
* Gravity Perks // GP Copy Cat // Copy Credit Card Name to Name Field
* http://gravitywiz.com/
*/
gform.addFilter( 'gppc_copied_value', function( value, $targetElem, field ) {
if( field.source.split( '.' ).pop() != 5 ) {
return value;
}
$source = jQuery( '#input_' + field.sourceFormId + '_' + field.source.split( '.' ).join( '_' ) );
if( $source.parents( '.ginput_container_creditcard, .ginput_container_custom_card_fields' ).length <= 0 ) {
return value;
}
// Stripe removes the "name" attribute so that the input's value is not submitted; GPCC does not account for this
// so let's get the value from our source input.
value = $source.val();
var $span = $targetElem.parents( 'span' );
if( $span.hasClass( 'name_first' ) ) {
value = value.split( ' ' ).shift();
} else if( $span.hasClass( 'name_last' ) ) {
values = value.split( ' ' );
values.shift();
value = values.join( ' ' );
}
return value;
} );
</script>
@Wordna1
Copy link

Wordna1 commented Apr 10, 2022

Replacing "ginput_container_creditcard" with "ginput_container_custom_card_fields" makes this snippet compatible with the PayPal Checkout PayPal Field. The Custom CSS Class for the PayPal Field will be formatted like "copy-4.5-to-8.3 copy-4.5-to-8.6"

@spivurno
Copy link
Author

@Wordna1 Thanks for the tip! Added it the class list so it'll support both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment