1

I want to be able to re-direct a user after creating a node of a specific content type and then display a message.

How can I accomplish this? Is the best way by using rules modules or custom module ?

With a custom module, I do not know what hook I would have to use in order to trigger after content type is been publish.

I know that I can use the drupal_goto to redirect them + and used the drupal_set_message to create a notification.

On the another hand, I know that using rules can be used to accomplish some of all this work.

1

The rules module can act on a "A new node has been created" event and has both "Page redirect" and "Display a message to a user" actions.

1

If you use modules like Ubercart or Drupal Commerce, you already have Rules module enabled. I'm not personally a fan of Rules module due to difficulties in migrating content and because the module is heavy to accomplish a few tasks.

You have few hooks you can implement.

  • hook_node_insert/update`: Executes on all node insert and update events, even the programmatic ones. Do NOT call drupal_goto() in such hook because it can break a lot of things and the remaining hooks will not run.
  • hook_form_alter: Go for this! Better yet you can improve the number of hook calls if you implement hook_form_node_form_alter (hook_form_BASE_FORM_ID_alter). You can check the node type inside the hook. If you implement hook_form_alter, make sure you validate the $form_id.

While in the form alter hook, add your custom submit handler, which can then set the form redirect destination and display the message.

<?php

function MYMODULE_form_node_form_alter(&$form, &$form_state) {
  // Validate node type and other conditions here.
  $form['#submit'][] = 'MYMODULE_SOME_APPROPRIATE_FUNCTION_NAME';
}

function MYMODULE_SOME_APPROPRIATE_FUNCTION_NAME($form, &$form_state) {
  $form_state['redirect'] = 'somewhere/you/want/to/redirect';
  drupal_set_message(t('Some message you want to display'));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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