[dynamic_select* subject placeholder:Please select include_blank dtx_disable_blank "CF7_POST key='subject_name'" "Subject example 1" "Subject example 2" "Subject example 3" "Subject example 4" "Subject example 5"]
Code used for the Form action button:
<form action="https://example.com/contactform/" method="post">
<input type="hidden" name="subject_name" value="Subject example 3">
<button name="Kontakt" title="Kontakt aufnehmen">Kontakt aufnehmen</button>
</form>
It would be great if you could help me here by giving me a functional example of how the code should look correctly and what needs to be written in the functions.php.
Thanks so much
Best regards
Werner
I’m encountering an issue with a select field dynamically populated using a custom function. The select field is populated correctly, but in the email sent, the values assigned to the [select_dynamic]
and [_raw_select_dynamic]
tags are identical.
After conducting various tests, I noticed that if I manually insert the post ID in the line of code “$date_corso = get_field('date_del_corso', get_the_ID());"
making it, for example, “$date_corso = get_field('date_del_corso', 9863);
“, everything works perfectly, and the values in the email are correctly submitted.
Of course, I’ve already verified that the value returned by get_the_ID()
is correct.
Here’s the entire code:
function dynamic_select_field_values ( $scanned_tag, $replace ) {
if ( $scanned_tag['name'] != 'select_dynamic' )
return $scanned_tag;
$date_corso = get_field('date_del_corso', get_the_ID());
if (isset($date_corso)) {
foreach ($date_corso as $d) {
$today = strtotime(date('Ymd'));
$data = get_field('data_corso', $d);
$location = get_field('location_corso', $d);
$timestamp = strtotime($data);
setlocale(LC_TIME, 'it_IT.utf8');
$giorno_testuale = ucfirst(strftime('%A', $timestamp));
$giorno_numerico = date('d', $timestamp);
$mese_testuale = ucfirst(strftime('%B', $timestamp));
$anno_numerico = date('Y', $timestamp);
$option = $giorno_numerico . " " . $mese_testuale . " " . $anno_numerico . " - " . $location;
if($today < strtotime($data)) {
$scanned_tag['raw_values'][] = $d . '|' . $option;
}
}
}
$pipes = new WPCF7_Pipes($scanned_tag['raw_values']);
$scanned_tag['labels'] = $pipes->collect_afters(); // this is the html info for each option
$scanned_tag['pipes'] = $pipes; // this is separator
$scanned_tag['values'] = $pipes->collect_befores(); // this is the value for each option
return $scanned_tag;
}
add_filter( 'wpcf7_form_tag', 'dynamic_select_field_values', 10, 2);
Thank you in advance for your help and suggestions!
]]>[dynamic_select licencie id:licencie class:select "source:filter"]
And here is the full code snippet:
add_filter( 'cf7sg_custom_dynamic_select','licencie_dynamic_options',10,3);
function licencie_dynamic_options($options, $tag, $cf7_key){
if('form-1'!==$cf7_key || 'licencie' !== $tag->name){
return $options;
}
global $wpdb;
$sql = "SELECT id, CONCAT(firstname, ' ', lastname) AS fullname FROM {$wpdb->prefix}_mytable";
$datas = $wpdb->get_results($sql);
foreach($datas as $row){
$data[$row->id] = $row->fullname;
}
foreach($data as $value=>$label){
$options[$value]=$label;
}
return $options;
}
But I can’t get values, all I get is the first letter of fullname. What did I missed? Shall I return a json array instead of a PHP one?
If I display $options (var_export), I have this:
array (
1 => 'John Doe',
2 => 'Mary Doe',
)
But in my form, there is:
<select value="" id="licencie" name="licencie" class="wpcf7-form-control cf7sg-dynamic-list cf7sg-dynamic_select wpcf7-dynamic_select select">
<option value="1">J</option>
<option value="2">M</option>
</select>
Can you help me please?
]]><select id="select">
<option value="1" data-foo="dogs">this</option>
<option value="2" data-foo="cats">that</option>
<option value="3" data-foo="gerbils">other</option>
</select>
]]>$choices = array(
‘– Make a Selection –‘ => ”,
value_1 => array( ‘Element 1’, ‘optgroup_1’ ),
value_2 => array( ‘Element 2’, ‘optgroup_1’ ),
value_3 => array( ‘Element 3’, ‘optgroup_1’ ),
value_4 => array( ‘Element 4’, ‘optgroup_2’ ),
value_5 => array( ‘Element 5’, ‘optgroup_2’ ),
value_6 => array( ‘Element 6’, ‘optgroup_3’ ),
value_7 => array( ‘Element 7’, ‘optgroup_3’ ),
);
This could also lead to improve the dropdown adding the possibility of more customisation for each element:
value => array( ‘Label’, ‘optgroup’, ‘class string’, ‘id’, ‘javascript’ ),
Thanks in advance for your great plugin.
]]>https://www.ads-software.com/plugins/contact-form-7/
]]>I’m going to try modifying the code shared in the categories dropdown thread; and am going to wait for a reply on the subcategories thread as I also want to show parent-child relationships among the terms in my taxonomy.
https://www.ads-software.com/plugins/contact-form-7-dynamic-select-extension/
]]>