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' => 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
<?php
/**
* @file
* TEST - File search inc.
*/
/**
* Implements hook_form().
*/
function test_services_search_form($form, &$form_state) {
$form['search'] = [
'#type' => 'container',
];
// Transfer.
$form['search']['transfer'] = [
'#ajax' => [
'callback' => 'test_services_search_transfer_callback',
],
'#attributes' => [
'class' => ['js-select2', 'cancel'],
'required' => TRUE,
],
'#title' => t('Transfer'),
'#options' => [
0 => t('Direct trip'),
1 => t('Stopover trip'),
],
'#type' => 'select',
];
return $form;
}
/**
* Callback handler for the direct/transfer trip select.
*/
function test_services_search_transfer_callback($form, &$form_state) {
$form_state['rebuild'] = TRUE;
}
/**
* Callback function.
*/
function test_services_search_form_callback($form, &$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?