Berming
Berming

Reputation: 1302

How to access a form in a custom form handler

I'm using the following logic to add a custom handler to a form that's defined by another module. I'm trying to do additional processing on the form data.

function my_module_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'my_form') {
    $form['#submit'][] = 'my_additional_submit_handler';
  }
}

Of course I define my own handler called my_additional_submit_handler

function my_additional_submit_handler(){

}

but how do I pass the form and its values to my custom handler? I tried passing &$form, but could not access it in the custom handler with dsm. Is there a special syntax to pass in arguments with the custom form handler?

Upvotes: 1

Views: 187

Answers (2)

Sandy DeLeon
Sandy DeLeon

Reputation: 662

Are you looking for the data in $form_state['values']['fieldName']? Also, as iKid mensioned in his code sample you need the args $form and $form_state in your handler function.

Upvotes: 2

w00d
w00d

Reputation: 5596

have you tried this ? It should work as expected:

function mymodule_form_alter(&$form, $form_state, $form_id) {  
  if($form_id=="your_form"){
    $form['#submit'][] = 'mymodule_form_mysubmit';
  }
}

function mymodule_form_mysubmit($form, &$form_state){
    // $form is your entire form object
    // $form_state should be your submitted data
}

Upvotes: 3

Related Questions