0

I have built a very simple module which just implements a block with a custom form. When submitted, the content is emailed to me. I show this block on the dashboard, and without the admin overlay it works totally fine.

But when I access the dashboard in the overlay and submit the form, I get no feedback at all (I user drupal_set_message() when the email is sent, but that doesn't show up) and half a minute later I find 437 copies of the same email in my inbox.

Unfortunately I have no idea at all where I could start debugging THIS. Maybe the overlay is just a coincidence. But what else could cause this massive submission of email and/or the form?

Any ideas are appreciated.

Thanks,

Victor

UPDATE: The (simplified) code below, this very basic form still has the same problem. How is this possible?

<?php

function mvp_form_test_block_info() {
  $blocks = array(
    'mvp_form_test_test_block' => array(
      'info' => 'Test Form',
      'cache' => DRUPAL_CACHE_GLOBAL,
      'properties' => array(
        'administrative' => true,
      ),
    ),
  );
  return $blocks;
}

function mvp_form_test_block_view($delta='') {
  if ($delta != 'mvp_form_test_test_block')
    return array();

  return array(
    'title' => 'Test Block',
    'content' => drupal_get_form('mvp_form_test_test_form'),
  );
}

function mvp_form_test_test_form($form, &$form_state) {
  $form = array();
  $form['sometext'] = array(
    '#type' => 'textfield',
  );
  $form['button'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );
  return $form;
}

function mvp_form_test_test_form_submit($form, $form_state) {
  watchdog('mvp_form_test', 'Form submitted with text '.$form_state['values']['sometext']);
  drupal_set_message('Form submitted with text '.$form_state['values']['sometext']);
}

?>
2
  • Please show your code, it's basically impossible to help without seeing that
    – Clive
    Commented Apr 29, 2013 at 12:01
  • I still have the same problem, but I managed to make the form as basic as possible. It's now a very short script, and instead of sending email it just generates a watchdog entry. Same thing happens. Gets submitted hundreds of times in the admin overlay on the dashboard, regardless of the browser. Here: pastebin.com/M6wV1wTm
    – medienvp
    Commented Apr 29, 2013 at 17:16

1 Answer 1

0

Not sure what is exactly causing this, but maybe you can use a static variable as a workaround for this issue.

function mvp_form_test_test_form_submit($form, $form_state) {
  $sent =& drupal_static(__FUNCTION__);
  if(!$sent) {
    watchdog('mvp_form_test', 'Form submitted with text '.$form_state['values']['sometext']);
    drupal_set_message('Form submitted with text '.$form_state['values']['sometext']);
    $sent = true;
  }
}

Your Answer

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

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