Description

Fires on form submit to load the URL needed for the redirect.

Parameters

$url
(string) URL for the redirect.
$form_id
(int) Form ID.
$form_data
(array) Processed form settings/data, prepared to be used later.
$fields
(array) Sanitized field data.
$entry_id
(int) Entry id.

Source

wpforms/includes/class-process.php

More Information

The wpforms_process_redirect_url filter that will be used to for the redirect once the form submits.

Examples

In this example, we’re going to set up the form for a redirect in the form builder settings, then based on a specific question on the form, redirect the user to different URLs based on the answer.

/**
 * Redirect URL.
 *
 * @link https://wpforms.com/developers/wpforms_process_redirect_url/
 *
 * @param string     $url       URL to redirect to.
 * @param int        $form_id   The form ID.
 * @param array      $form_data Processed form settings/data.
 * @param array      $fields    Sanitized fields data.
 * @param int        $entry_id  Entry id.
 *
 * @return string
 */
   
function wpf_dev_process_redirect_url( $url, $form_id, $fields, $form_data, $entry_id ) {
     
// Only run on my form with ID = 879.
    if ( absint( $form_data['id'] ) !== 879 ) {
        return $fields;
    }
	// Assign the checkbox field that shows the room number to a variable
	$room_number = $fields[4]['value']; 
	
	if ($room_number === "Room A") {
		
		// Redirect to page with Room A information
		$url = 'http://myexamplesite.com/room-a-info';
	} 
	    elseif ($room_number === "Room B") {
			
			// Redirect to page with Room B information
			$url = 'http://myexamplesite.com/room-b-info';
		} 
		    elseif ($room_number === "Room C") {
			
			// Redirect to page with Room C information	
			$url = 'http://myexamplesite.com/room-c-info';
		} 
	    else {
			
			// Keep the current redirect URL that is set in the form builder settings
			$url = $url;
		}
	
    return $url;
}
add_filter( 'wpforms_process_redirect_url', 'wpf_dev_process_redirect_url', 10, 5 );


If the user selects to reserve Room A, the form will ignore the URL from the form builder’s redirect settings on the Confirmations tab and instead redirect to a URL containing information about Room A. The loop continues through the options listed for each room with a fallback in the final else and keep the original URL from the form builder settings.

Snippet Reference: How to Preserve the Query Strings in the URL on Form Submit