Skip to content

Instantly share code, notes, and snippets.

@gicolek
Created November 4, 2025 14:21
Show Gist options
  • Select an option

  • Save gicolek/ca615659ec8a2b86163d63e2a88dd976 to your computer and use it in GitHub Desktop.

Select an option

Save gicolek/ca615659ec8a2b86163d63e2a88dd976 to your computer and use it in GitHub Desktop.
Gravity Forms submit one form values to another form
<?php
add_action( 'gform_after_submission_n', 'wpdoin_after_submission_add_n_form_submission', 10, 2 );
/**
* Create a submission associated with the XYZ form, upon submitting the form with ID N. I.e. use the N form values to populate
* the XYZ form entries.
*
* @hook gform_after_submission_x
*/
function wpdoin_after_submission_add_n_form_submission( $entry, $form ) {
// get the form values
$fn = rgar( $entry, '1' );
$ln = rgar( $entry, '3' );
$email = rgar( $entry, '4' );
$sth = rgar( $entry, '5' );
$submission_data = [
'input_1' => $fn,
'input_3' => $ln,
'input_4' => $email,
'input_5' => $sth,
];
// https://gist.github.com/rxnlabs/1bd931bb0261e53e882e9e7315bae8dc
unset( $_POST['input_1'] );
unset( $_POST['input_3'] );
unset( $_POST['input_4'] );
unset( $_POST['input_5'] );
// Submit the form programmatically
$result = GFAPI::submit_form( 1, $submission_data );
// Check if submission was successful
if ( is_wp_error( $result ) ) {
// remove the echoes, if necessary. They will display below the form notification, if present.
echo 'An unidentified error occurred. Please try again later.';
// (think of logging the error instead) error_log ( $result->get_error_message() );
} else {
echo 'Form submitted successfully!';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment