views:

42

answers:

2

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?

+3  A: 

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
}
iKid
have you tried to clear the cache ? Did your function work without the parameter?Also I just read this, maybe you could try the approach here as wellhttp://drupal.org/node/144132#custom-params
iKid
This should work. If it doesn't, and because dsm("string") doesn't work neither, I suspect your are not altering the form at all. Check your $form_id in your hook_form_alter.
mongolito404
+2  A: 

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.

MisterBigs