Plugin Planet

Premium WordPress Plugins

USP Pro makes it easy to set custom redirects to any URL after the form is submitted. This works out of the box, but success and error messages need to be added manually. This quick tutorial explains an easy way to implement response messages for custom redirects.

UPDATE: New USP Pro add-on now available! The new add-on automatically displays success and error messages when custom redirects are enabled. So you can either implement your own solution as described in the following tutorial, or contact us to purchase a copy of the add-on »

Step 1: Implementing custom redirects

There are two ways to set custom redirects, globally and locally (per form):

Global custom redirects are set in the plugin settings under Advanced > Form Configuration > “Redirect URL for Success” and “Redirect URL for Failure”. You can learn more about these settings in this tutorial on Custom Redirects for USP Pro. After specifying a value for either of these settings, it will be used for all forms unless a local value is set.

Local custom redirects

Setting a custom redirect for any form, add the [usp_redirect] shortcode, like so:

[usp_redirect url=""]

With this in place, the visitor will be redirected to after submission. Learn more about local redirects in the tutorial Custom Redirects for USP Pro.

Note that if you are not using custom redirects, you can set your own success and error messages via the plugin settings, under the “Advanced” and “More” tabs. Otherwise, they need to implemented manually. Read on to learn how it’s done.

Step 2: Understanding redirect parameters

Once you have a custom redirect in place, after submitting the form, the visitor will be redirected to the specified URL with one of the following parameters included in the query string:

  • usp_success – successful form submission
  • usp_error_n – failed form submission (where n = the error number)

These parameters will be included in the URL, so it will look something like this:


Equipped with this information, we are ready to implement success and error messages for our custom redirect.

Step 3: Implementing custom success and error messages

To add a message that is displayed when the form is submitted successfully, add the following code to the desired location in your theme template file:

if (isset($_GET['usp_success'])) echo "Success! Post submitted..";

Likewise, to display a message when the form submission is not successful, we can add the following to the associated theme file:

if (isset($_GET['usp_error_1'])) echo "Ooops! Error 1";

With USP Pro, there are numerous errors that can be customized, for example:

<?php // custom error messages

if (isset($_GET['usp_error_1'])) echo "Ooops! Error 1";
if (isset($_GET['usp_error_2'])) echo "Ooops! Error 2";
if (isset($_GET['usp_error_3'])) echo "Ooops! Error 3";

// ...


That code would be included in whichever theme template is used to display your custom error page. Here is a complete list of USP Pro Error Definitions. Probably don’t need to define a message for every error, just the ones that are relevant to the form in question.

Integrating via functions.php

Instead of including the above code in “whichever theme template is used to display your custom error page” (as suggested previously), you can include via your theme’s functions.php file. Here is an example:

function usp_custom_error_messages() {
	if (isset($_GET['usp_error_1'])) echo "Ooops! Error 1..";
	if (isset($_GET['usp_error_2'])) echo "Ooops! Error 2..";
	if (isset($_GET['usp_error_3'])) echo "Ooops! Error 3..";
add_action('init', 'usp_custom_error_messages');

The trick here is hooking our custom function into WP’s init hook, which enables us to check the $_GET variable for the specified parameters. Here is another example showing how to hook a custom success function:

function usp_custom_success_message() {
	if (isset($_GET['usp_success'])) echo "Success! Post submitted..";
add_action('init', 'usp_custom_success_message');

Going the init route via functions.php (or custom plugin) is a good way to keep your other theme template files neat and organized. Also keep in mind that for success messages, the $_GET variable includes the Post ID, so you can grab that and do some amazing things.

Of course, this is just a basic guide to get you started. Using the magic of PHP and the WP API, it’s possible to do very advanced things with success and error messages for custom form redirects. Note: eventually this functionality will be built in to the plugin, but for now it must be implemented manually.