spivurno
1/26/2018 - 3:13 AM

Gravity Perks // GP Copy Cat // Copy Credit Card Name to Name Field

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>