Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By creativepragmatic on
I am currently working on a custom registration form module. While there are a lot of posts about this, none of them really provide a clear picture of how to populate a select list from taxonomy terms programmatically.
The machine name of the taxonomy terms is 'cities'. Here is the code so far:
$form['cities'] = array(
'#type' => 'select',
'#title' => t('Click on your city'),
'#multiple' => true,
'#options' => ???,
'#description' => t('Click on one or more cities.'),
);
Comments
just insert a field in the
just insert a field in the form select the type as term refernce and then select the taxonomy term as city.
the field is populate...
I do not have extensive
I do not have extensive module development experience so I am not sure how to express this in PHP code. Is this what you mean?
me too don't have module
me too don't have module development experience , but as the term reference are multiple I think there should be some kind of loop to fetch all the values..
sorry If I am wrong..
This is what I ended up
This is what I ended up with:
I hoped to find a function that would take the machine name of the taxonomy term and return results that match the query. I checked the taxonomy functions but didn't find anything that would do this. Is there a more elegant way of expressing this?
It doesn't help with the
It doesn't help with the name/id thing, but there is a function called taxonomy_get_tree that is helpful with this kind of things so you don't have to query the db yourself.
Henrik Akselsen | frontkom | Twitter: @FrontHenrik
That's why I couldn't find a
That's why I couldn't find a function in Drupal Core. I was being too specific in my search. taxonomy_get_tree is a more generic function than what I was searching for. Thank you for taking the time to explain that Henrik.
Here's how to do it in Drupal
Here's how to do it in Drupal 7, for those looking:
Thanks for updating an old thread!
I was just looking for a solution and found the answer in your recent post. THANKS!
So useful code in most of
So useful code in most of cases.
Thank you for sharing this nice solution.
Pushpinder Rana #pushpinderdrupal
Acquia Certified Drupal Expert
select in an API form
Thanks.
It's easy to do it ... with help ...
Manuel Ruiz Alvarez
Lima - Perú
South America
Excellent and consise
Thanks for this snippet, it is exactly what the doctor ordered, clean and to the point.
Thanks
By this way it was easy to solve filling a select list in an API form.
Thank you.
Manuel Ruiz Alvarez
Lima - Perú
South America
And It's taxonomy_form() In D6
In case anyone else was looking for the Drupal 6 version of this answer:
It doesnt work for me
I already have my taxonomy vocabulary but it does return an empty array ?
any advice ?
Thanks
This is working for me..
This is working for me...Thank you
Use autocmplete for a FAPI
I have found this link that helped me a lot : http://drupal.stackexchange.com/questions/78899/display-a-taxonomy-terms...
Manuel Ruiz Alvarez
Lima - Perú
South America
<?phptaxonomy_get_tree($vid);
$terms = taxonomy_get_tree($vid);
building elegant solutions efficiently
$results = db_query("SELECT
This does not works for me..
This does not works for me..Anyway thank you
helper function
- try this function to get vocabulary and pass it to options :
Simplest way