tags:

views:

47

answers:

1

I'm writing a module that acts on another module. The other module's submit form is at admin/settings/image-toolkit. When its form is submitted, my module needs to respond to that event.

What hook do I need to listen for and how do I know the name of the form?

I'm not even sure where to print dsm in this case to get more information about this form. Is there something like hook_nodeapi but for forms that I could give me more info about the form?

+3  A: 

All forms come with a $form[#submit] property that describes what functions are run when the form submits. The default is formname_submit, of course, but you just need to add new ones to that array.

So, you should use hook_form_alter and add another item to the $form['#submit'] array.

You can get the form id easily using the Devel module, or by looking for in the HTML of the pages themselves. (Hyphens should be translated to underscores if you take the latter route)

I get system_image_toolkit_settings for that form on my installations, but that might be dependent on which image library you're using (I use GD).

Though, I'll admit I'm scratching my head a bit about what submit handlers you're wanting to add to that one ;p

Edit:

Some sample code in reply to OP's comment:

What you're basically looking for is this: (from http://drupal.org/node/144132)

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

Of course, you'll need to follow that up with function my_additional_submit_handler in your custom module for anything to happen.

anschauung
To get more info about any particular form, I would suggest going into the module itself and inspecting the code, or maybe dropping a dpm($form) line temporarily into the form function.
anschauung
You *are* adding to the form itself ... sort of. :) hook_form_alter lets you add an additional handler function to its '#submit' array, so the form knows to run your function when the form is submitted. I've edited my post with some sample code.
anschauung
Of course, your submit handler should read from $form_state['values'] just like any other form_submit function. $form won't return anything useful once the form is submitted :)
anschauung
Glad I could help :)
anschauung