I am creating a simple basic module that alters the text of a submit button and should change the default creation message with drupal_set_message().

I've found an example about changing the message, and changed the code a little.

 function ask_admin_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == "vragen_node_form") {
     $form['actions']['submit']['#value'] = 'Stel Uw Vraag';
     $form['buttons']['submit']['#submit'][0] = 'ask_admin_node_form_submit';

 function ask_admin_node_form_submit($form, &$form_state) {
   global $user;

   $node = node_form_submit_build_node($form, $form_state);
   $insert = empty($node->nid);
   $node_link = l(t('view'), 'node/'. $node->nid);
   $watchdog_args = array('@type' => $node->type, '%title' => $node->title);
   $t_args = array('@type' => node_get_types('name', $node), '%title' => $node->title);

   if ($insert) {
     watchdog('content', '@type: added %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
     drupal_set_message(t('Uw vraag is met succes ontvangen en zal zo spoedig mogelijk beantwoord worden.', $t_args));
   else {
     watchdog('content', '@type: updated %title.', $watchdog_args, WATCHDOG_NOTICE, $node_link);
     drupal_set_message(t('U heeft uw vraag met succes gewijzigd.', $t_args));
   if ($node->nid) {
     $form_state['nid'] = $node->nid;
     $form_state['redirect'] = 'node/'. $node->nid;
   else {
     // In the unlikely case something went wrong on save, the node will be
     // rebuilt and node form redisplayed the same way as in preview.
     drupal_set_message(t('Er ging iets mis bij het verzenden van uw vraag.'), 'error');

Although the form button is indeed changed to my own text, the message won't change when the node is created.

When I copy and paste the whole tutorial, my node messages won't change, but I also get no error messages.

Does anyone knows what is wrong, or how I can change the message using other code?

3 Answers 3


Change $form['buttons']['submit']['#submit'][0] to $form['actions']['submit']['#submit'][0] in your HOOK_form_alter().

I don't know why that tutorial has you modifying the $form['buttons'] array. Very few forms will put something as important as the primary Submit button outside of $form['actions'], and certainly not a core form.

  • Thanx man!!! Worked like a charm. To bad i can't accept the answer yet(someone else can?) neither can i vote up. So if anyone reads this, please give eclecto some points.
    – Arjan
    Aug 8, 2013 at 15:03

This: $form['buttons']['submit']['#submit'][0] = 'ask_admin_node_form_submit';

Should be this: $form['#submit'] = array('ask_admin_node_form_submit'); if you want to completely override default form processing.


You can suppress the message with https://www.drupal.org/project/disable_messages with a regex rule like:

Vraag .*? has been created.

or if translated

Vraag .*? is aangemaakt.

Then add your own custom message with Rules or with drupal_set_message() in a HOOK_form_alter()

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.