dynamic select
-
I’m trying to get some datas from a mysql database, here is the tag:
[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?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘dynamic select’ is closed to new replies.