I need to be able to compare 4 number fields when a user submits the form and then based on which number field is highest they go to the appropriate page.
Is there currently a way to do this? I’ve seen posts where it says you have to create your own PHP and then you can use snippets after that, but I need a more concrete answer if anyone is able to help.
// Change 1 on the following to your form id number.
add_action( 'gform_pre_submission_1', 'calculate_highest_field' );
function calculate_highest_field( $form ) {
// Replace "field 1", "field 2", etc. with whatever you want
// Replace the input numbers with the ID numbers of your number fields
$numbers = array(
'field 1' => $_POST['input_1'],
'field 2' => $_POST['input_2'],
'field 3' => $_POST['input_3'],
'field 4' => $_POST['input_4'],
);
$highest_number = array_key_first( arsort( $numbers ) );
// Change "5" to the ID if your hidden field
$_POST['input_5'] = $highest_number;
}
You’ll need to make a few changes to the code to make it work with your form - you need to change the IDs of the form and the fields to match your form.
After you have done that, you can go to the form settings page, and go to the confirmation settings. Add a new confirmation. In the confirmation settings, you can configure conditional logic for the confirmation. The hidden field will have a value of “field 1”, “field 2”, “field 3”, or “field 4” - whichever one has the highest number.
That’s a broad overview of how to do it. If you need more detail, let me know!