Skip to content
Home » Documentation » Contact Form 7 – Dynamic Text Extension

Contact Form 7 – Dynamic Text Extension

Overview

Contact Form 7 – Dynamic Text Extension (DTX) is a very simple plugin that extends the functionality of Contact Form 7.

Out-of-the-box in Contact Form 7, you can set a static default value for text inputs. For example, if you have a field with a “name” input, you could set the default of that field to “John” and the name field would then be pre-filled with the text “John” when the user visits the page.

DTX allows you to set this default dynamically, with the value generated by a shortcode. A more useful default value for “name” would dynamically return the logged-in user’s name instead of the static “John.” The value is no longer static (“John”), but dynamic in that it changes based on who is viewing the form.

In short, DTX allows you to set the text that appears by default in a text or hidden input via shortcodes. Developers can further customize these form control elements with dynamic attributes and choices! Check out some of the demonstrations below.

    Contact Form 7 FieldDTX Field

    Static default value is typed in

    [text cf7-text-value "Hello World"]

    Dynamic default value is the title of the current page

    [dynamic_text dtx-text-value "CF7_get_current_var key='post_title'"]

    Can only set a static placeholder text or a default value, not both!

    [text cf7-text-placeholder placeholder "Hello World"]

    Can dynamically set both placeholder text and a default value separately! Delete all the text in this text input to see it.

    [dynamic_text dtx-text-placeholder placeholder:CF7_get_current_var%20key%3D%26%2339%3Btitle%26%2339%3B "CF7_guid"]

    Used CF7_guid for the default value and CF7_get_current_var key='title' for the placeholder

    Static id attribute is typed in: hello-world

    [text cf7-text-id-attr id:hello-world]

    Inspect my source code to see!

    Dynamic id attribute is the slug of the current page: CF7_get_current_var key='slug'

    [dynamic_text dtx-text-id-attr id:CF7_get_current_var%20key%3D%26%2339%3Bslug%26%2339%3B]

    Inspect my source code to see!

    Static class attributes are typed in: hello-world

    [text cf7-text-class-attr class:hello-world]

    Inspect my source code to see!

    Dynamic class attribute is the slug of the current page: CF7_get_current_var key='slug'

    [dynamic_text dtx-text-class-attr class:CF7_get_current_var%20key%3D%26%2339%3Bslug%26%2339%3B]

    Inspect my source code to see!

    Static placeholder option for drop-down menu

    [select static-select include_blank "Apples" "Bananas" "Dragonfruit"]

    Dynamic placeholder option is also optionally configurable to be hidden and disabled

    [dynamic_select dynamic-select include_blank placeholder:Select%20a%20fruit dtx_hide_blank dtx_disable_blank "Apples" "Bananas" "Dragonfruit"]

    Requirements

    1. An input element of type text, hidden, email, url, tel, number, range, checkbox, radio, date, submit in addition form controls textarea, select, and label.
    2. A self-closing shortcode that returns a value that can be rendered as text for text-based inputs or a JSON encoded object for selection-based controls.
    3. A value that can be determined server-side (as all shortcodes are processed server-side with the exception for cache plugin compatibility)

    Out of Scope

    The Contact Form 7 – Dynamic Text Extension does not:

    • work with form field controls other than what was listed above.
    • change field values based on user interactions (you need JavaScript for that)
    • provide a shortcode for every conceivable use case (but you can create custom shortcodes for your unique cases)

    Related Post Module Attributes Before

    array(29) {
      ["post_type"]=>
      string(4) "post"
      ["post_id"]=>
      string(1) "0"
      ["exclude"]=>
      string(1) "0"
      ["title"]=>
      string(32) "Related Articles & Tutorials"
      ["description"]=>
      string(0) ""
      ["max"]=>
      string(1) "3"
      ["post_ids"]=>
      string(0) ""
      ["exclude_ids"]=>
      string(0) ""
      ["is_series"]=>
      string(0) ""
      ["featured_term"]=>
      string(6) "307,72"
      ["exclude_terms"]=>
      string(0) ""
      ["exclusive"]=>
      string(1) "1"
      ["order"]=>
      string(4) "DESC"
      ["show_image"]=>
      string(2) "on"
      ["image_size"]=>
      string(6) "medium"
      ["menu_order_label"]=>
      string(0) ""
      ["show_order_label"]=>
      string(2) "on"
      ["show_date"]=>
      string(2) "on"
      ["show_meta_keys"]=>
      string(2) "on"
      ["show_modified"]=>
      string(0) ""
      ["show_author"]=>
      string(0) ""
      ["show_categories"]=>
      string(0) ""
      ["show_primary_category"]=>
      string(0) ""
      ["show_description"]=>
      string(0) ""
      ["show_reading_time"]=>
      string(2) "on"
      ["show_cta"]=>
      string(2) "on"
      ["cta"]=>
      string(9) "Read more"
      ["autoplay"]=>
      string(0) ""
      ["allow_sticky"]=>
      string(0) ""
    }
    

    Related Post Module Attributes

    array(29) {
      ["post_type"]=>
      string(4) "post"
      ["post_id"]=>
      string(1) "0"
      ["exclude"]=>
      string(1) "0"
      ["title"]=>
      string(32) "Related Articles & Tutorials"
      ["description"]=>
      string(0) ""
      ["max"]=>
      string(1) "3"
      ["post_ids"]=>
      string(0) ""
      ["exclude_ids"]=>
      string(0) ""
      ["is_series"]=>
      string(0) ""
      ["featured_term"]=>
      string(6) "307,72"
      ["exclude_terms"]=>
      string(0) ""
      ["exclusive"]=>
      string(1) "1"
      ["order"]=>
      string(4) "DESC"
      ["show_image"]=>
      string(2) "on"
      ["image_size"]=>
      string(6) "medium"
      ["menu_order_label"]=>
      string(0) ""
      ["show_order_label"]=>
      string(2) "on"
      ["show_date"]=>
      string(2) "on"
      ["show_meta_keys"]=>
      string(2) "on"
      ["show_modified"]=>
      string(0) ""
      ["show_author"]=>
      string(0) ""
      ["show_categories"]=>
      string(0) ""
      ["show_primary_category"]=>
      string(0) ""
      ["show_description"]=>
      string(0) ""
      ["show_reading_time"]=>
      string(2) "on"
      ["show_cta"]=>
      string(2) "on"
      ["cta"]=>
      string(9) "Read more"
      ["autoplay"]=>
      string(0) ""
      ["allow_sticky"]=>
      string(0) ""
    }