How to execute ajax into block view I'm in Drupal 7. I would like to execute an ajax function in my front-page. I've defined the block view in my ".module" file. When I change the selected option, the log gets two errors:

1.


  Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'test_services_search_form' not found or invalid function name in drupal_retrieve_form() (line 842 of /var/www/html/test/html/includes/form.inc).    


2.


  Notice: Undefined index: test_services_search_form in drupal_retrieve_form() (line 807 of /var/www/html/test/html/includes/form.inc).


test.module

function test_services_block_info() {
  $blocks['test_services_search_form'] = [
    'info' =&gt; t('Plan your trip'),
  ];
  return $blocks;
}

function test_services_block_view($delta = '') {
  $block = [];
  switch ($delta) {
    case 'test_services_search_form':
      module_load_include('inc', 'test_services', 'includes/test');
      $form             = drupal_get_form('test_services_search_form');
      $block['content'] = render($form);
      break;
  }
  return $block;
}


test.inc

&lt;?php

/**
 * @file
 * TEST - File search inc.
 */

/**
 * Implements hook_form().
 */
function test_services_search_form($form, &amp;$form_state) {
  $form['search'] = [
    '#type' =&gt; 'container',
  ];

  // Transfer.
  $form['search']['transfer'] = [
    '#ajax'       =&gt; [
      'callback' =&gt; 'test_services_search_transfer_callback',
    ],
    '#attributes' =&gt; [
      'class'    =&gt; ['js-select2', 'cancel'],
      'required' =&gt; TRUE,
    ],
    '#title'      =&gt; t('Transfer'),
    '#options'    =&gt; [
      0 =&gt; t('Direct trip'),
      1 =&gt; t('Stopover trip'),
    ],
    '#type'       =&gt; 'select',
  ];

  return $form;
}

/**
 * Callback handler for the direct/transfer trip select.
 */
function test_services_search_transfer_callback($form, &amp;$form_state) {
  $form_state['rebuild'] = TRUE;
}

/**
 * Callback function.
 */
function test_services_search_form_callback($form, &amp;$form_state) {
  return $form;
}


The point is disable three fields if option two is selected, It's possible execute AJAX into a block view, and if so, what is going on? Why Drupal is not going into the function of the AJAX callback?
I've defined the block view. When I change the selected option, the log gets two errors.


It seems the error happens after you submitting the block. So the file loads fine on view, but not when the form is processed which should have information where to look for it.

So you should define your form using hook_forms.


  By default, when drupal_get_form() is called, the system will look for a function with the same name as the form ID, and use that function to build the form. If no such function is found, Drupal calls this hook.


Also, when you working with the forms, instead of drupal_get_form($form_id), you can consider using form_load_include() to make sure the include file is loaded whenever the form is processed.


  Use this function instead of module_load_include() from inside a form constructor or any form processing logic as it ensures that the include file is loaded whenever the form is processed. In contrast to using module_load_include() directly, form_load_include() makes sure the include file is correctly loaded also if the form is cached.