By shanghaiguide on
I'm getting issues with generating a taxonomy dropdown in 4.7
- I have two issues
One is that the code outputs the correct dropdown, but generates this in the logs.
implode(): Bad arguments. in /home/drupal/public_html/includes/form.inc on line 291.
The second is that the #default_value isn't getting selected.
(They could be related).
Anyone care to look, and see what I'm doing wrong?
function countrydata_dropdown ($current_country) {
//Show country as select dropdown
$countries = taxonomy_get_children(0,variable_get('country_vocabulary', false));
$countries_array = array();
$countries_array[0] = t('Country');
foreach ($countries as $country) {
$countries_array[$country->tid] = $country->name;
}
$form['country'] = array(
'#type' => 'select',
'#title' => '',
'#name' => 'countryselect',
'#id' => 'countryselect',
'#default_value' => $current_country,
'#options' => $countries_array,
'#description' => '',
'#attributes' => array('onChange' => 'top.location.href=document.getElementById("countryselect").options[document.getElementById("countryselect").selectedIndex].value')
);
//Output the form
$output= form_render($form[country]);
return ($output);
}
Comments
Found my own answer...
I'm using the wrong function - instead of form_render, its drupal_get_form.
The default value works as well now...
So last line before return ($output); changes to:
And voila, all happy now.
The docs are a little fuzzy on some things. I guess thats the price of progress to 4.7...
-=-=-=-=-=-=-=-=-=-=-=-=-=-=
http://www.shanghaiguide.com
Thank you!
Shangai, thank you, my dropdown menu now works just fine thanks to your tip!
(actually a developer told me it wasn't possible to fix, and a patch to taxonomy was needed for a total of 6 hours of work.. yours is a much more easy, effective and affordable solution! :)