Redirect Fluent Forms Based on an Answer
Sends visitors to a different page after submitting a Fluent Forms form depending on an answer, such as separate thank-you pages for each service.
Opens WPIDE on
Code
$wpide_ff_redirect_form = 0; // Form ID (0 = off until you set it).
$wpide_ff_redirect_field = 'department'; // Field name holding the answer.
$wpide_ff_redirect_map = array(
'sales' => '/thank-you-sales/',
'support' => '/thank-you-support/',
);
add_filter( 'fluentform/form_submission_confirmation', function ( $confirmation, $data, $form ) use ( $wpide_ff_redirect_form, $wpide_ff_redirect_field, $wpide_ff_redirect_map ) {
if ( (int) $form->id !== $wpide_ff_redirect_form || ! is_array( $confirmation ) ) {
return $confirmation;
}
$answer = isset( $data[ $wpide_ff_redirect_field ] ) && is_scalar( $data[ $wpide_ff_redirect_field ] ) ? (string) $data[ $wpide_ff_redirect_field ] : '';
if ( isset( $wpide_ff_redirect_map[ $answer ] ) ) {
$confirmation['redirectTo'] = 'customUrl';
$confirmation['customUrl'] = esc_url_raw( home_url( $wpide_ff_redirect_map[ $answer ] ) );
$confirmation['enable_query_string'] = 'no';
}
return $confirmation;
}, 10, 3 );
Notes
Set the form ID, the field name and the answer-to-URL map at the top; other answers keep the form's normal confirmation.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.