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, a
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:
[submit]
Simply add this to your functions.php
file
add_filter('wpcf7_form_tag_data_option', function($n, $options, $args) {
if (in_array('gigs', $options)){
$gigs = array(
"MAY 07 - NEW ORLEANS, LA",
"MAY 09 - AUSTIN, TX",
"MAY 12 - HOUSTON, TX"
);
return $gigs;
}
return $n;
}, 10, 3);
Now 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/