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); }