How to concatenate 2 fields in a Gravity Form?
I have 2 fields in my form for the first name and last name, and I need to get the full name in a single field. How can I combine these 2 fields into a third?
Add this code to your plugin or function file:
<?php /* * concatenates fields 1 and 2 into field 3 for form #10 */ add_action( 'gform_pre_submission_10', 'wpster_get_fullname' ); function wpster_get_fullname($form) { $_POST['input_3'] = rgpost('input_1').' '.rgpost('input_2'); } ?>
If you want to repeat the same operation for several forms, use this syntax:
<?php add_action( 'gform_pre_submission', 'wpster_get_fullname' ); function wpster_get_fullname($form) { // form #1 Contact if ( $form['id'] == 1 ) { $_POST['input_9'] = rgpost('input_1').' '.rgpost('input_3'); } // form #3 Reservations if ( $form['id'] == 3 ) { $_POST['input_18'] = rgpost('input_1').' '.rgpost('input_3'); } /* complete with other forms... */ } ?>