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].

1 Answer 1

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;
1
  • I have used this. its giving me above result.
    – Amit Kumar
    Commented Jan 15, 2018 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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