在表单验证Drupal之后执行Ajax回调

在表单验证Drupal之后执行Ajax回调,ajax,drupal,drupal-7,drupal-8,Ajax,Drupal,Drupal 7,Drupal 8,我在Drupal8中有表单,在hook\u form\u alter中我试图发出Ajax请求 function helloworld_form_alter(&$form, $form_state, $form_id) { if ($form_id == 'contact_message_feedback_form') { $form['actions']['submit']['#ajax'] = array( 'wrapper' => 'form_wrapper', '

我在Drupal8中有表单,在hook\u form\u alter中我试图发出Ajax请求

function helloworld_form_alter(&$form, $form_state, $form_id) {

if ($form_id == 'contact_message_feedback_form') {

$form['actions']['submit']['#ajax'] = array(
  'wrapper' => 'form_wrapper',
  'callback' => 'custom_callback',
  'event' => 'click',
  'progress' => [
  'type' => 'throbber',
  'message' => 'Veryfieng'],
  );  

$form['test_selection'] = [
  '#type' => 'hidden', 
  '#prefix' => '<div id="form_wrapper">',
  '#suffix' => '</div>',
  '#weight' => 100,
];
  }
} 



 function custom_callback($form, &$form_state) {
   $output = array();

   $output['#markup'] = 'Thank you! Your message has been sent!';

   return $output;
 }
函数helloworld\u form\u alter(&$form、$form\u state、$form\u id){
如果($form\u id=='contact\u message\u feedback\u form'){
$form['actions']['submit']['#ajax']=array(
'wrapper'=>'form_wrapper',
“回调”=>“自定义回调”,
'事件'=>'单击',
“进度”=>[
'type'=>'throbber',
'消息'=>'VeryFing'],
);  
$form['test_selection']=[
“#类型”=>“隐藏”,
“#前缀”=>”,
“#后缀”=>”,
“#重量”=>100,
];
}
} 
函数自定义_回调($form,&$form_状态){
$output=array();
$output['#markup']=“谢谢!您的邮件已发送!”;
返回$output;
}
这是可行的,但整个验证功能被忽略。
如何在调用custom_callback()之前验证表单

不要使用自定义Ajax回调,请尝试以下代码,它将调用表单的submitForm()方法,从而在调用submitForm()之前也调用validateForm()方法


简而言之,它将通过Ajax提交表单。

不要使用自定义Ajax回调,请尝试以下代码,它将调用表单的submitForm()方法,从而在调用submitForm()之前也调用validateForm()方法

简而言之,它将通过Ajax提交表单

$form['actions']['submit'] = array(
  '#attributes' => array (
     'class' => array (
         'use-ajax-submit'
     ), 
  ),
  '#ajax' => array(
     'wrapper' => 'form_wrapper',
  )
);