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.
Requirements
- An
inputelement of typetext,hidden,email,url,tel,number,range,checkbox,radio,date,submitin addition form controlstextarea,select, andlabel. - 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.
- 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)