I need to delete the message "Your vote was recorded." when a user votes in a poll.

I tried comment the line containing drupal_set_message(t('Your vote was recorded.')) in the Poll module, but if I do this, the Poll Enhancements module doesn't work well.

What other way has Drupal 7 for deleting specific messages?

link|improve this question

59% accept rate
Editing a Drupal module is never suggested; if you update Drupal, you should editing the module all times. – kiamlaluno Feb 22 at 21:59
yes, you are right. What alternative is there for delete this message in the poll? Thanks for your answer. – cabita Feb 22 at 22:08
feedback

1 Answer

The messages set with drupal_set_message() are saved in $_SESSION['messages'][$type] as an array of strings ($type can be "status", "warning", or "error"). The message you see, is set in poll_vote(), which is the form submission handler used for processing a vote, used from poll_view_voting(), the form builder for the vote form.

In order to remove the show string you should:

  • Implement hook_form_FORM_ID_alter() to add a form submission handler that is executed after poll_vote().
  • Implement the form submission handler to remove the string added from poll_vote().

Code similar to the following one should work.

function mymodule_form_poll_view_voting_alter(&$form, &$form_state) {
  $form['vote']['#submit'][] = 'mymodule_poll_view_submit';
}

function mymodule_poll_view_submit($form, &$form_state) {
  if (isset($_SESSION['messages']['status']) && is_array($_SESSION['messages']['status'])) {
    $messages = array_flip($_SESSION['messages']['status']);
    unset($messages[t('Your vote was recorded.')]);
    $_SESSION['messages']['status'] = $messages;
  }
}
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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