Infusionsoft: Redirecting After Submitting Web Form Version 2

I was asked today how could I route users to different pages using the value of a dropdown list and thought my original version of the routing function would work perfectly but it did not. It required a little tweaking but here you go…

Infusionsoft Web Form

For my example, I created another simple Web Form at I set the Thank You page for this form as a Web Address ->

Shortcode Verion 2

Version 2 of the shortcode –

[esifs_router_v1 field_name="inf_custom_BlogInterests" pages = '{"Digital Downloads":"","Infusionsoft":"","How Tos":""}']

Where the field_name (inf_custom_BlogInterests) that I want to interrogate is named and the values of the choices (Digital Downloads, Infusionsoft, How Tos) and the pages I want visitors redirected to follow in the variable pages.

SelectRedirect to Page
Digital Downloads
How Tos

If you take a peek at the source code of my web form, you will notice that each of the items in the dropdown has the values that you entered in the field in the Infusionsoft web form builder.

<div class="infusion-field"> 
   <label for="inf_custom_BlogInterests">Blog Interests *</label> 
   <select id="inf_custom_BlogInterests" name="inf_custom_BlogInterests">
      <option value="">Please select one</option>
      <option value="Digital Downloads">Digital Downloads</option>
      <option value="Infusionsoft">Infusionsoft</option>
      <option value="How Tos">How Tos</option>

To enable the use of such a shortcode requires that I add a function to my WordPress theme’s function.php file. I’ll explain what the following code does line by line below.

add_shortcode('esifs_router_v2', 'esifs_router_v2_function');
function esifs_router_v2_function($atts, $content = null){
    //* What is the IFS field name we are concerned with that predicts the routing
    if ((isset($atts["field_name"]) && $atts["field_name"] != "") && (isset($atts["pages"]) && $atts["pages"] != "")) {
        //* Convert the pages to a proper array
        $pages = json_decode( $atts["pages"], true );
        if( !is_array( $pages ) or count( $pages )<1 ) $pages = array();
        //* Get the value of the IFS field
        $field_name = $atts["field_name"];
        //* Make sure there is a value
        if (isset($_GET[$field_name]) && $_GET[$field_name] != "") {
            $value = $_GET[$field_name];
            $url = $pages[$value];
            if ($url != "") {
                $string .= '<script type="text/javascript">';
                $string .= 'window.location = "' . $url . '"';
                $string .= '</script>';
                echo $string;
            } else {
                echo "<p>No value found.</p>";
  • Line 1: Associates the shortcode [esifs_router_v2] with the function esifs_router_v2_function. WordPress now knows that when it sees the shortcode [esifs_router_v2] in a page or post, it will call the esifs_router_v2_function. For more on WordPress shortcodes, you can read Smashing Magazines guide on shortcodes.
  • Line 3: passes the attributes from the shortcode to the function esifs_router_v2_function.
  • Line 5: checks to ensure that the field name is set in the shortcode and not empty.
  • Line 7 – 8: converts the details of the pages parameter into an array to use in the rest of the code.
  • Line 11: tells the function what field name I want to check for redirection. In my case, it is the field name inf_option_MyInterest.
  • Line 14: checks to ensure that the field name is being passed to the page by Infusionsoft and that the value is not empty.
  • Lines 15: assign the value of the option the visitor selected to the variable $value.
  • Lines 16: assigns the appropriate URL to the variable $url.
  • Lines 18 – 21: Will output a small piece of Javascript to the page that will redirect the visitor to the page you defined in the shortcode.
  • Lines 22 – 23: If a URL is not found in the array, it will output a message without the JavaScript code to redirect.

To finish this post I wanted to show you how to change the shortcode from my original example so that I could use the new version of the shortcode.

The new shorcode would look like –

[esifs_router_v2 field_name="inf_option_MyInterest" pages='{"213":"", "215":"", "217":""}']

Leave a Reply