I’ve been trying to figure out how to populate input fields in contact forms on my WordPress website. I’ve tried using a plugin called Contact Form 7 dynamic text extension, and tried a pretty simple IF statement with PHP. But i just can’t seem to get this to work.
With the plugin, i can only get half of the arguments to work in the shortcode, even then the form doesn’t properly validate.
Using PHP as a placeholder=”” outputs the code instead of the contents of the variable. for example “$current_user->user_firstname”
Any help on the matter would be much appreciated.
You can install this plugin
Contact Form 7 Dynamic Text Extension
Dynamic text and dynamic hidden fields are available using it.
And you can use the following code to grab the current user info into your field.
Or as mentioned in the answer above:
Note also that you can use
dynamichidden
for hidden fields like the followingPS: I faced an issue with required hidden fields when I tried to use this
dynamichidden*
, the shortcode appears on my website as a plain text.Turns out, i wasn’t using the shortcode correctly.
These are the shortcodes i’ve used in with Contact Form 7 Dynamic text extension:
Let’s say you have an PHP array
$gigs
, and you want to display it as a drop down list in your form like this:Simply add this to your
functions.php
fileNow your drop down field should look like this:
Source: https://bdwm.be/dynamically-populate-a-contact-form-7-dropdown-list-or-any-other-input-field/
I have done this before. Instead of using the PHP code as a placeholder. Use jQuery, for example: