Drupal 7 add ajax listener directly to node form I'm trying to register an ajax listener to a checkbox on one of my standard node forms. I want to display certain regions of the form only in case, the field is checked. I can get the drupal ajax ecosystem to work, when I use it in a custom form, but I'm unable to make it work on my node forms.

First I hook into form_alter to check if I'm with the node type I want to add the listener for:

function interceptor_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if($form_id === 'film_node_form') {
    interceptor_dvd_listener($form, $form_state);
  }
}


Then I try to attach the ajax stuff to my checkbox, which name is field_dvd:

function interceptor_dvd_listener(&amp;$form, &amp;$form_state) {
  $form['field_dvd'] = array(
    '#title' =&gt; t('You want to display DVD informations too?'),
    '#type' =&gt; 'checkbox',
    '#ajax' =&gt; array(
      'callback' =&gt; 'interceptor_dvd_listener_callback',
      'wrapper' =&gt; 'checkboxes-div',
      'effect' =&gt; 'slide',
      'progress' =&gt; array('type' =&gt; 'none'),
    ),
  );
  return $form;
}


The function interceptor_dvd_listener_callback is never called. I try to print some debug information there, but nothing happens...

function interceptor_dvd_listener_callback($form, $form_state) {
  data_service_log_object($form);
}


UPDATE

After passing $form as reference to interceptor_dvd_listener the ajax callback function got called like expected. I edited my code above.
This interceptor_dvd_listener_callback() should return value, in documentation:


  After form processing is complete, ajax_form_callback() calls the
  function named by #ajax['callback'], which returns the form element
  that has been updated and needs to be returned to the browser, or
  alternatively, an array of custom Ajax commands.


Why don't you use this:
https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7#states

It is drupal 7 standard feature to hide or show some fields when some elements has some states.