Ankh2054
Ankh2054

Reputation: 1153

Drupal node creation - back to origin after creation

I have organic groups setup and within those group users are allowed to post certain content. What I woulkd like to do is, when you create a node inside an organic group, it automatically defaults back to frontpage of the group, or the same page that I used to create the node.

At present it defaults to the node view page.I assume there must be a way to add some kind of code so that after the node creation it defauls back to its origin. I.E. the page from where the node was created from.

thanks :)
UPDATE: Got the below, but not entirly sure how to ensure that it redirects back to the GROUP node, from where it was created,

<?php 

/**
* Grabs current node ID
*/

$node_nid = nid; 

/**
* Implements hook_form_alter().
*/
  function mod_form_alter(&$form, $form_state) {
  $form['buttons']['submit']['#submit'][] = 'mod_form_finish_redirect';
  unset($form['buttons']['preview']);
}

/**
 * Custom submit handler. Overwrites the form redirection variable.
 */

function mod_form_finish_redirect($form, &$form_state) {
  $form_state['redirect'] = '/content/<?php print $node_nid; ?>';
}
?>

Upvotes: 0

Views: 1297

Answers (3)

Satya
Satya

Reputation: 3128

I had the same requirment. Rules worked for me.

Upvotes: 0

marcvangend
marcvangend

Reputation: 5642

Rules (as 'We Love Drupal' says) is a possibility, but also quite a big module for such a small change in behavior. Another option is to write a custom module implementing hook_form_alter setting the #redirect value of the form.

Keep in mind that of seeing the node you have just created is important feedback for a user. When you perform an action, you want confirmation that you have achieved your task. While it's technically possible to do what you ask, it may be bad for usability.

Upvotes: 0

SnapShot
SnapShot

Reputation: 5544

I would recommend the rules module. Rules is a great module that allows you to do many kinds of workflow and it is perfect for this. You can write a rule that triggers when a specified node type is created (and include any other conditions you require as well). After the node is created you can specify a redirect action rule to the home page. This can all be done without any code.

Upvotes: 1

Related Questions