Contact Form 7 is a great plugin to add forms to your site, but these forms contain static inputs and sometimes we require to add inputs with dynamic values like a post ID or PHP variables like GET and POST.

This is very easy to do with the plugin Contact Form 7 Dynamic Text Extension.

This plugin adds two additional tag types to the Contact Form 7 plugin, these two types are Dynamic Text field and Dynamic Hidden field, the dynamic value for a scpecif input is generated throught a shortcode.

The plugin has it’s own shortcodes integrated, but you can create your own.

Let me put a very simple example:

Lets say you want to add a hidden input in your form which value should be the current post ID.
If you create your own shortcode it would look like this:

function cf7_add_post_id(){
 
    global $post;
    return $post->ID;
}
 
add_shortcode('CF7_ADD_POST_ID', 'cf7_add_post_id');

And the dynamic field in your form setup would look like this:

[dynamictext my-filed-name "CF7_ADD_POST_ID"]

The other way would be to use the plugin’s shortcodes.
In this case we want to have the current post ID so you would only have to add your dynamic field in the form setup like this:

[dynamictext my-filed-name "CF7_get_post_var key='ID'"]

The plugin has shortcodes for GET, POST, blog info, post info, current URL, custom fields, current user info, referrer URL.
You have all the details in the plugin’s page on wordpress.org

How to add dynamic values into Contact Form 7 inputs
Tagged on:

9 thoughts on “How to add dynamic values into Contact Form 7 inputs

  • January 7, 2016 at 15:27
    Permalink

    Hi,
    my form is build on 4 tabs with cf7 skin multi and in the last tab I would like to summurize the previous input using the dynamic text extension. Have you any idea about how i can get previous input and insert them on the last tab as dynamic text?

    Really Thank You

    Luca

    Reply
  • December 13, 2016 at 07:58
    Permalink

    Hi,

    How to add dynamic input text field after select dropdown value in contact form 7

    Reply
  • March 2, 2017 at 21:47
    Permalink

    How would I go about adding the following in:

    It’s a cookie, but hidden – to get the URL.

    Reply
  • May 8, 2017 at 08:09
    Permalink

    goddamn thank you!!!! your simply example has helped me no end – i have been trying to get this to work for a number of days with no help from the community. well done.

    Reply
  • June 18, 2017 at 05:56
    Permalink

    I’m really enjoying the theme/design of your blog. Do you ever run into any browser compatibility issues? A small number of my blog audience have complained about my website not working correctly in Explorer but looks great in Firefox. Do you have any advice to help fix this problem?
    bestdayonraiditem.tumblr.com https://bestdayonraiditem.tumblr.com/

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *