Infusionsoft: Redirecting After Submitting Web Form

Update 3/6/15: I was asked today if this code would work with values from a dropdown listbox. I said it would but once I looked at the values within the dropdown listbox I saw that my approach had a flaw. I tweaked the code.
You can see it in this newer post.


I’ve seen the question asked more than once recently – “I’m using Infusionsoft and I want to redirect my site visitors to specific pages on my site depending upon the options they select in a Web Form, how can I do this?”

My clients are predominately WordPress users and I wanted to see how easy it would be to create a page router without the use of a plugin. Ideally, I wanted a shortcode that would be simple to use and easy to remember. Something like –

[esifs_router field_name="inf_option_MyInterest" 213="http://clients.equalserving.com/loreen/infusionsoft-router/213-kayaking" 215="http://clients.equalserving.com/loreen/infusionsoft-router/215-biking" 217="http://clients.equalserving.com/loreen/infusionsoft-router/217-hiking"]

Where the field name (inf_option_MyInterest) that I want to interrogate is named and the values of the choices (213, 215, 217) and the pages I want visitors redirected to follow in a list.

For my example, I created a simple Web Form at https://fr381.infusionsoft.com/app/form/page-router. I set the Thank You page for this form as a Web Address -> http://clients.equalserving.com/loreen/infusionsoft-router/

If you take a peek at the source code of my Web Form, you will notice that each of the radio button options has a unique value assigned by Infusionsoft. The field name is inf_option_MyInterest and the values are 213 for Kayaking, 217 for Hiking and 215 for Biking.

<div class="infusion-field"> 
   <label for="inf_option_MyInterest">My Interest *</label> 
   <div class="infusion-radio"> 
      <span class="infusion-option"> 
         <input id="inf_option_MyInterest_213" name="inf_option_MyInterest" type="radio" value="213" /> 
         <label for="inf_option_MyInterest_213">Kayak</label> 
      </span> 
      <span class="infusion-option"> 
         <input id="inf_option_MyInterest_215" name="inf_option_MyInterest" type="radio" value="215" /> 
         <label for="inf_option_MyInterest_215">Bike</label> 
      </span> 
      <span class="infusion-option"> 
         <input id="inf_option_MyInterest_217" name="inf_option_MyInterest" type="radio" value="217" /> 
         <label for="inf_option_MyInterest_217">Hike</label> 
      </span> 
   </div> 
</div> 

The goal is to have my site visitors redirected to a page that is very specific to their selected interests. Therefore, I have created three different pages. They will be redirected as follows:

  • If you select Kayaking, the value is set to 213 and you will be redirected to http://clients.equalserving.com/loreen/infusionsoft-router/213-kayaking
  • If you select Hiking, the value is set to 217 and you will be redirected to http://clients.equalserving.com/loreen/infusionsoft-router/217-hiking
  • If you select Biking, the value is set to 215 and you will be redirected to http://clients.equalserving.com/loreen/infusionsoft-router/215-biking

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', 'esifs_router_function');
function esifs_router_function($atts, $content = null){
	if (isset($atts["field_name"]) && $atts["field_name"] != "") {
		$field_name = $atts["field_name"];
		if (isset($_GET[$field_name]) && $_GET[$field_name] != "") {
		$value = $_GET[$field_name];
		$url = $atts[$value];
	    $string .= '<script type="text/javascript">';
    	$string .= 'window.location = "' . $url . '"';
    	$string .= '</script>';
	    echo $string;
	}
}
  • Line 1: Associates the shortcode [esifs_router] with the function esifs_router_function. WordPress now knows that when it sees the shortcode [esifs_router] in a page or post, it will call the esifs_router_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_function.
  • Line 4: checks to ensure the the field name is set in the shortcode and not empty.
  • Line 5: tells the function what field name I want to check for redirection. In my case, it is the field name inf_option_MyInterest.
  • Line 6: checks to ensure that the field name is being passed to the page by Infusionsoft and that the value is not empty.
  • Lines 7: assign the value of the option the visitor selected to the variable $value.
  • Lines 8: assigns the appropriate URL to the variable $url.
  • Lines 9,10,11: Will output a small piece of Javascript to the page that will redirect the visitor to the page you defined in the shortcode.

Like everything, there is more than one way to do it. This is what I came up – it would be interesting to know what others would do.