Hi.

I was working on implementing a form the other day and I ran into an issue where I had to catch a form submit event. After looking here and there and asking around I was pointed out to use the hook_form_submit for this, however, when I implement it it's not triggered and I also can find it on api.drupal.org.

This page http://api.drupal.org/api/file/developer/topics/forms_api.html seems to be discussing the hook but for me this doesn't seem to work when I implement it.

Is there something I'm doing wrong?

Thanks,
Luke

PS: It's also not listed on the regular cheat sheets (http://drupal.org/node/212648).

Comments

esend7881’s picture

If I understand you question, you want "something to happen" after the submit button is hit?

Have you looking into the hook_form_validate()?

http://api.drupal.org/api/function/node_type_form_validate

I recall a similar issue and was able to use this function to modify what happens after on validation.

However, with me it was for incorrect data. Are you instead looking to redirect someone after they hit submit?

kannan@kiluvai.com’s picture

hi,

In Drupal 6 they have made some changes in the Form API, they changed the submit handlers

here is it, explained clearly about the differences http://drupal.org/node/144132 kindly go through.

there is always hook_form_submit and additional feature is you can have separate submit function for each button

$form['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#access' => !in_array($menu['menu_name'], menu_list_system_menus()),
      '#submit' => array('menu_custom_delete_submit'),
      '#weight' => 10,
    );

here in above example we call separate function for delete button in #submit attribute.

in the same way you can also have custom function for the form submit

function menu_form_alter(&$form, $form_state, $form_id) {
   ... 
    $form['menu']['parent'] = array(
      '#type' => 'select',
      '#title' => t('Parent item'),
      '#default_value' => $default,
      '#options' => $options,
      '#attributes' => array('class' => 'menu-title-select'),
    );
    $form['#submit'][] = 'menu_node_form_submit';
}

in the above example through form alter we are assigning the custom submit function to the form

all reference are from http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...

pan69’s picture

Ah. There you go. If you're not aware of this change it's quite difficult to figure out.

Not sure why the change, it's still as cryptic as ever... :)

hardalex’s picture

function hook_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'submit':

break;
case 'insert':

break;
}