How to Preserve the Query Strings in the URL on Form Submit


Do you want to preserve the query strings in the URL when your form submits? If you’re using the Dynamic Field Choices but want to preserve those URLs when the form submits, a simple PHP snippet is all that is needed to accomplish this. In this tutorial, we’ll show you the PHP needed to preserve these strings when the form submits.

By default, when you’ve created your form to accept Dynamic Field Choices and query strings, once the form submits, this URL is replaced with the default page URL.


The code shown below will retain the URL, including the query strings and dynamic choices, when the form submits.

Simply copy and paste this code into your site.

 * Preserve the query strings in the URL on form submit.
 * @link

function wpf_dev_process_redirect_url() {
	global $wp;
	$current_url = home_url( add_query_arg( array( $_GET), $wp->request ) );
	return $current_url;
add_filter( 'wpforms_process_redirect_url', 'wpf_dev_process_redirect_url' );

With the PHP snippet above the query string will remain in the URL on the form submission

And that’s all you need to keep the query strings in the URL after submission. Would you like to learn how to use the User Registration addon to automatically log your users in once the registration is complete? Take a look at our tutorial on How to Automatically Log in Users After Registration.

Filter reference: wpforms_process_redirect_url