I'm trying to connect a field of a taxonomy term to a field in a content type, something like this:

Auto-Fill from on content type to another

I tried this on a node and it's working, but now I have some problems with the taxonomy term, is for this part?

// load node by nid
$node = node_load($nid);

Do I have to specify here the taxonomy? but I really don't know what to put in...

the field in content type is "field_descrizione_01" with empty field "field_udm" the field with the data in the taxonomy terms is "field_udm_ti"

I've made this code (based on the link one):

* Implements hook_field_widget_form_alter().

function collegamento_field_widget_form_alter(&$element, &$form_state, $context) {

  if(isset($element['#field_name']) && $element['#field_name'] == 'field_descrizione_01') {
    $element['#ajax'] = array(
      'callback' => 'collegamento_auto_fill_callback',

function collegamento_auto_fill_callback(&$form, &$form_state) {

  $commands = array();

  if(isset($form_state['values']['field_descrizione_01'])) {
    // get selected item/node from dropdown list
    $nid = $form_state['values']['field_descrizione_01']['und'][0]['nid'];

    // load node by nid
    $node = node_load($nid);

    if($node) {

      if(isset($node->field_udm_ti['und'])) {
        // fill text field 
        $commands[] = ajax_command_invoke('#edit-field-udm', 'val', array($node->field_udm_ti['und'][0]['value']));  


  return array('#type' => 'ajax', '#commands' => $commands);
  • Hello. Please post actual code you are using. We cannot reliably guess what changes you made already to make it work with taxonomy.
    – Mołot
    Sep 9, 2013 at 12:15
  • hello! i've posted it above
    – luca
    Sep 9, 2013 at 12:27
  • Maybe I've found the problem, I've used the field collection module, I've tried to change the #edit-field-udm part but it's still not working... Somebody knows how to fix it?
    – luca
    Sep 11, 2013 at 13:34

1 Answer 1


You need to load a taxonomy term using taxonomy_term_load

This should get you on the right track.

  • Hello, thanks. I've tried to change $node = node_load($nid); in $node = taxonomy_term_load($nid); but not working. Do I have to change other terms?
    – luca
    Sep 10, 2013 at 7:04

Your Answer

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

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