0

I am using Drupal 7. I have created a content type with autocomplete taxonomy field. I need to set default value programmatically. I am using this code under hook_form_alter:

$form['field_school_locality_city_level'][LANGUAGE_NONE]['names']['#default_value'] = tid;

It's giving me just term id, but I need it in format Bhopal[tid:8193].

| improve this question | | | | |
3

Load taxonomy term using term id then, generate data in your required format.

 // Term id.
 $tid = 8193;   
 // Obtain the term. 
 $term = taxonomy_term_load($tid);
 // Format data.
 $data = $term->name . '[tid:' . $tid .']';

$form['field_school_locality_city_level'][LANGUAGE_NONE]['names']['#default_value'] = $data;
| improve this answer | | | | |
  • I have used this. its giving me above result. – Amit Kumar Jan 15 '18 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.