1

In a drupal 6 custom module I built, I have a menu callback which contains this:

function mymodule_register_confirmation() {
  return drupal_get_form('mymodule_newsletter_form');
}

I have the function that returns the form:

function mymodule_newsletter_form(&$form_state) {
  $form = array();

  $form['logo'] = array(
    '#type' => 'markup',
    '#value' => '<div class="logo-header">',
  );

  ...

  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit')
  );

  ...

  return $form;
}

I also built the function for the submit hook of newsletter form:

function mymodule_newsletter_form_submit($form, &$form_state) {
    die('I am in the submit hook!!');
}

The page shows as expected and contains the newsletter form exactly as I want. However, when I click the submit button, it goes to the action of the form (as expected) but the submit hook I built never executes. I even tried adding the following to the function that returns the form:

$form['submit']['#executes_submit_callback'] = TRUE;
$form['#submit'][] = 'mymodule_newsletter_form_submit';

What am I doing wrong?

Thanks in advance.

5
  • Are you clear the cache? Generally, $form['#submit'][] should work. Also try to add a validation handler and find out it is invoked - $form['#validate'][] = 'mymodule_newsletter_form_validaton';
    – Sithu
    Nov 14, 2012 at 6:52
  • Is your module name is mymodule_newsletter Nov 14, 2012 at 8:57
  • @SithuKyaw: added the validation handler it is not called either. Nov 14, 2012 at 14:19
  • @SumitMadan: no, this test module is called "mymodule". Nov 14, 2012 at 14:20
  • @RolandPish Please change the name mymodule_newsletter_form to mymodule_form and check. Nov 15, 2012 at 4:46

2 Answers 2

1

Ahhhh, found the problem!

I had to specify manually a redirect to the form:

$form['#redirect'] = ''; // Redirects to the home page

This way the validate and submit hooks are called appropriately and then it redirects to the home page.

Thank you all for all your replies. I appreciate it.

Cheers.

0

Without the additional $form['#submit'][] = 'mymodule_newsletter_form_submit';, your code works just fine as is (pasted into a clean d6 install). There has to be something else going on that's preventing the submit handler from executing.

1
  • Mmm, interesting. I will have to dig in into the other custom modules to see if something is going on in there. Thanks a lot Sean! Nov 14, 2012 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.