Gform_pre_submission not working

I’ve inserted this into the functions.php file and upon submit of the multi-page form it just spins and never completes (i.e if “hangs”).

I am attempting to take the values from two drop down fields (107, 81) and concatenate them into field 108. I’m doing this because I want to map field 108 to a Salesforce field using CRM Perks Salesforce plugin.

// Combine two field values into a single value on Receiving Agency Registration Form ID 31 //.
add_action( ‘gform_pre_submission_31’, ‘pre_submission_handler’ );
function pre_submission_handler($form) {
// Change 14 and 5 to the id number of your fields.
$_POST[‘input_108’] = rgpost( ‘input_107’ ).rgpost( ‘input_81’ );
}

When I remove the function the form submits and works as expected.

Any reason this would not work?

Hi Sean,

The main issue was that the original code didn’t properly handle cases where one or both of the dropdown fields might be empty, and it wasn’t properly returning the form object back to Gravity Forms.

Here’s the corrected code that should work for you:

add_action('gform_pre_submission_31', 'pre_submission_handler');

function pre_submission_handler($form) {
    $field_107_value = rgpost('input_107') ? rgpost('input_107') : '';
    $field_81_value = rgpost('input_81') ? rgpost('input_81') : '';
    
    $_POST['input_108'] = $field_107_value . $field_81_value;
    
    return $form;
}

We now check if each field has a value before trying to use it. This prevents potential errors that could cause the form to hang. We’ve also added a proper return statement for the form object, which Gravity Forms expects to receive back. We store the field values in variables first, making the code more reliable and easier to troubleshoot if needed.

This solution should allow your form to submit successfully while still combining the values from fields 107 and 81 into field 108 as desired for your Salesforce integration.

Please try implementing this updated code and let me know if you experience any further issues. I’m here to help if you need any additional assistance.

Screenshots:


Perfect. Thank you.

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