开发者

Drupal: run custom code when a form is submitted

开发者 https://www.devze.com 2023-02-11 04:45 出处:网络
how can I run specific 开发者_运维知识库code when a form is submitted in Drupal ? I\'m using hook_form_alter to edit the form, but I actually need to collect the data inserted by user and run code wh

how can I run specific 开发者_运维知识库code when a form is submitted in Drupal ?

I'm using hook_form_alter to edit the form, but I actually need to collect the data inserted by user and run code when the user click on "Save / Register" etc

thanks


You can add callbacks to the submit array. It goes something like this:

function myform_form_alter(&$form, &$form_state, $form_id) {
  if($form_id == 'some_form') {
    $form['#submit'][] = 'mycallback';
  }
}

function mycallback(&$form, &$form_state) {
// do stuff
}


Try adding the following function:

function myform_form_submit($form_id, $form_values){ 
        print_r($form_values);
        // custom code 
 }

worked for me. Hope it helps :)

0

精彩评论

暂无评论...
验证码 换一张
取 消