VantaBods
asked on
Drupal node creation - back to origin after creation
Hi All,
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; ?>';
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
But it just isn't right.
$form_state['redirect'] = '/path/to/group/page';
or just put this after data processing
drupal_goto('/path/to/grou
The point is '/path/to/group/page' should point to node's parent group, not the currend node that recently created.
Eg: if your path is /content/#group_id, where #group_id is the value of the group, and it is stored on the form, then the code might be something like this
$form_state['redirect'] = '/content/'. $form['group_id'];
btw, there're 2 points in your code that never work:
1. $form_state['redirect'] = '/content/<?php print $node_nid; ?>'; --> no, you will not have $node_id value.
It must be like this: $form_state['redirect'] = '/content/'. $node_nid;
2. $node_nid is defined outside of mod_form_finish_redirect()
function mod_form_finish_redirect($
global $node_nid;