All Collections
General
Developer Resources
Adding Dynamic Data to Your Autoresponder Code
Adding Dynamic Data to Your Autoresponder Code

This article will show you how to add dynamic data to your autoresponder code.

Thrive Themes avatar
Written by Thrive Themes
Updated over a week ago

Sometimes you may want to add dynamic data to your autoresponder code. For instance, you want to send details about which traffic source the visitor arrived from, or their IP address, in a hidden field.

Important!

The Autoresponder Code can only be added through the HTML Integration of an Opt-in Form. It does NOT work with an API Integration, since it uses a different approach.

In order to give you this ability, we have two ways that you can achieve this.

  1. By using shortcodes directly in your autoresponder code

  2. By hooking into our tve_additional_fields filter

Using Shortcodes in your Autoresponder

Thrive Architect and Thrive Leads will process shortcodes that are included in your form.

For instance, if you had the following:

[ip_address_field]

Then the ip_address_field shortcode would be searched for and executed (assuming that it existed).

This allows you to integrate any third-party plugin that provides dynamic data through shortcodes with your autoresponder forms through Thrive Leads.

If you're a developer, you can also easily create your own shortcodes that will enable you to have complete control over what data is sent. For example:

​/** example shortcode of how you can generate a dynamic input for use in your autoresponder code */
add_shortcode('tve_fields_shortcode',
'leads_fields');
/**
* Use this shortcode to return a dynamic code (perhaps additional fields) or tracking pixel
* Usage: [tve_fields_shortcode]
*/
function leads_fields() {
return '<input type="hidden" name="additional_leads_field" value="success">';
}

The simple code above registers a new shortcode and then outputs a hidden input where the shortcode [tve_fields_shortcode] is used.

Obviously, this is a useless implementation - but gives you an example of how you can create your own shortcodes to include a custom field.

Hook Into the tve_additional_fields Filter

To extend your options even further, we've added a filter that is automatically appended just before the </form> tag of your autoresponder code.

The filter passes three parameters:

  1. $lead_group - this is the WP post object for the lead group content type

  2. $form_type - this is the WP post object for the form_type content type (e.g lightbox, ribbon, widget)​

  3. $form_variation - this is an array of data of the form type variation that's being displayed

The filter sends an empty string as a variable and anything returned will be appended before the </form> tag.

This, again, allows you to inject dynamic code into your autoresponder. Here are some examples of how you can use the filter to load some additional fields:

/**
* Filter Example 1 - Attach to every form in TCB and Leads
*
* @param $lead_group - (WP Post Object) Lead Group content type
* @param $form_type - (WP Post Object) Form Type content type
* @param $form_variation - (Array) Form variation data
* @return string - additional dynamic code to appear before </form> tag
*/
function leads_additional_fields_ex1($additional_content, $lead_group, $form_type, $form_variation)
{
return $additional_content . "<input type='hidden' name='additional_leads_field_ex1' value='success'>";
}
add_filter("tve_additional_fields", "leads_additional_fields_ex1", 10, 4);
/**
* Filter Example 2 - Only apply logic to a lead group with a particular name*
* @param $additional_content - Might be empty or string added bug other filters before
* @param $lead_group - (WP Post Object) Lead Group content type
* @param $form_type - (WP Post Object) Form Type content type
* @param $form_variation - (Array) Form variation data
* @return string - additional dynamic code to appear before </form> tag
*/
function leads_additional_fields_ex2($additional_content, $lead_group, $form_type, $form_variation)
{
if(empty($lead_group)) {
return $additional_content;
}
$my_group_name = 'My Group 1';
if(is_object($lead_group) && $lead_group->post_title === $my_group_name) {
return $additional_content . "<input type='hidden' name='additional_leads_field_ex2' value='success'>";
}
return $additional_content;
}
add_filter("tve_additional_fields", "leads_additional_fields_ex2", 10, 4);
/**
* Filter Example 3 - Only apply logic to a lead group with a particular name and an individual form type
*
* @param $additional_content - Might be empty or string added bug other filters before
* @param $lead_group - (WP Post Object) Lead Group content type
* @param $form_type - (WP Post Object) Form Type content type
* @param $form_variation - (Array) Form variation data
* @return string - additional dynamic code to appear before </form> tag
*/
function leads_additional_fields_ex3($additional_content, $lead_group, $form_type, $form_variation)
{
if(empty($lead_group) || empty($lead_group)) {
return $additional_content;
}
$my_group_name = 'My Group 1';
$particular_form_type = 'Ribbon';
// $particular_form_type = 'Lightbox';
// $particular_form_type = 'Widget';
// $particular_form_type = 'Post Footer';
// $particular_form_type = 'Slide in';
// $particular_form_type = 'In content';
if(is_object($lead_group) && $lead_group->post_title === $my_group_name && is_object($form_type) && $form_type->post_title === $particular_form_type) {return $additional_content . "<input type='hidden' name='additional_leads_field_ex3' value='success'>";
}
return $additional_content;
}
add_filter("tve_additional_fields", "leads_additional_fields_ex3", 10, 4);

The above code shows you how you can use the filter to add an additional field to right before the </form> tag and also how you can use conditional logic and the parameters to target specific lead groups and form types on your site.

Use the Example Plugin on GitHub

We have created a plugin with a number of examples (including the two above) that you can download and install on your web site to use as a foundation for building your logic.

Be careful that you don't upload this plugin to your website and leave it activated without modification. If you do, it may add some unwanted fields to your autoresponder code.​

Integrating with your Autoresponder

Of course, in order for the data to be captured in your autoresponder, you'll need to make the necessary changes in the backend system of the autoresponder of your choice.

For instance, in Aweber, you'll need to set up a custom field that matches the name of the hidden input field that you're trying to send.​

If you don't do this correctly, then the data will be sent through the Thrive Leads form, however, it won't be picked up and stored in your autoresponder.

You should consult the documentation of the autoresponder service that you use in order to create the necessary custom fields. If you're having difficulty, your autoresponder's customer service team should be able to provide you with the necessary instructions.

Did this answer your question?