i am fairly new to drupal , i have custom button added to one the content type edit page , when i click on that button i want to call a function but it seems like it is not calling function when i see the console i see drupa ajax error coming whenever i click the button . please let me know what i am doing wrong here .
function mymodule_form_node_program_edit_form_alter(&$form, FormStateInterface $form_state) {
$form['apply'] = array(
'#type' => 'submit',
'#value' => t('Apply'),
'#weight' => '9',
'#executes_submit_callback' => FALSE,
'#limit_validation_errors' => array(),
'#ajax' => array(
'callback' => 'button_test_callback',
),
);
}
function button_test_callback(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
echo '<script>alert("Welcome")</script>';
return $form;
}
error i am getting :
Uncaught
Drupal.AjaxError {message: "\nAn AJAX HTTP error occurred.\nHTTP Result Code: 50…\Core\DrupalKernel->handle(Object) (Line: 19)\n", name: "AjaxError"}
message: "\nAn AJAX HTTP error occurred.\nHTTP Result Code: 500\nDebugging information follows.\nPath: /node/680911/edit?destination=/admin/content&ajax_form=1\nStatusText: error\nResponseText: The website encountered an unexpected error. Please try again later.Symfony\Component\HttpKernel\Exception\HttpException: The specified #ajax callback is empty or not callable. in Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse() (line 67 of core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php). Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber->onException(Object, 'kernel.exception', Object)\ncall_user_func(Array, Object, 'kernel.exception', Object) (Line: 111)\nDrupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.exception', Object) (Line: 227)\nSymfony\Component\HttpKernel\HttpKernel->handleException(Object, Object, 1) (Line: 79)\nSymfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 67)\nDrupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 57)\nDrupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)\nDrupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)\nDrupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)\nDrupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49)\nAsm89\Stack\Cors->handle(Object, 1, 1) (Line: 50)\nDrupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 47)\nDrupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)\nDrupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)\nStack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)\nDrupal\Core\DrupalKernel->handle(Object) (Line: 19)\n"