I want to copy only the first letter from lastname to an new Field

Hi, i want to use a Social Proof Tool, that say´s

Gerrit J from Hamburg has bought Product XYZ

So I need in the Process something, that copies Lastname in an other Field and removes
alle Letters instead of the First

So from Jensen to J
Is this Possible?

You can do this with the gform_pre_submission filter, to store the first name and first letter of the last name, in another field in the form. Then you can use values from that field in the entry in your social proof tool.

The code might look like this (if the Name field is field 1 on your site):

// Change 8 on the following line to your form id.
add_action( 'gform_pre_submission_8', 'return_first_letter' );
function return_first_letter( $form ) {
	// 1_3 is first name portion of field 1; 1_6 is last name portion of field 1
	$firstCharacterLast = substr( rgpost('input_1_6'), 0, 1 );
	// Assign the first name and first letter of last name to field 9
	$_POST['input_9'] = rgpost('input_1_3') . ' ' . $firstCharacterLast;
}

That is PHP code that can be added to your theme functions.php file, or you can use a plugin such as this one to keep the code separate from the theme: Code Snippets – WordPress plugin | WordPress.org

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.