aneuryzm
aneuryzm

Reputation: 64854

Drupal: run custom code when a form is submitted

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

Upvotes: 1

Views: 576

Answers (2)

Hasan
Hasan

Reputation: 33

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 :)

Upvotes: 0

Rimian
Rimian

Reputation: 38428

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
}

Upvotes: 5

Related Questions