Hook_form_submit not called

I am trying to submit a form and use hook_form_submit.

The problem is that the form is displayed through ajax, and this causes hook_form_submit not to be called.

$items['ajaxgetform/%'] = array(  
  'page callback' => 'ajaxgetform',  
  'access arguments' => array('access content'),  
  'type' => MENU_CALLBACK  
);   

function ajaxgetform($form_id) {    
  drupal_get_form($form_id);  
  return drupal_json($panel);  
}  

function_myform_form($form_state) {  
  $form['myform'] = array(  
    '#title' => 'myform value',  
    '#type' => 'textfield',  
    '#default_value' => 'myform default value'  
  );  

  $form['#action'] = url('myurl');

  $form['submit'] = array(  
    '#type' => 'submit',  
    '#value' => 'submit'  
  );

  $form['#ajaxsubmit'] = TRUE;  
    return $form;  
  }  

hook_form_alter() causes a call.

Below is not called?

function myform_form_submit($form, $form_state) {   
  // ...  
} 

I'm not sure this is a common problem, but I have been trying to get it working for hours.

If I delete $form['#action'] = url('myurl'); myform_form_submit(), it is called. However, I get a white screen with a jason script.

+3
source share
2 answers

No hook_form_submit(). Instead, you register submit handlers with $form['#submit']. So, if you want to call myform_form_submit()when submitting the form, add:

$form['#submit'][] = 'myform_form_submit';

myform_form(). 5.x 6.x API .

+8

myurl? , , ( drupal_get_form()) , .

#redirect URL #action. , URL-, .

0

Source: https://habr.com/ru/post/1756643/


All Articles