Solved

Drupal node creation - back to origin after creation

Posted on 2010-11-18
2
594 Views
Last Modified: 2012-05-10


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; ?>';
}
?>

Open in new window

0
Comment
Question by:VantaBods
2 Comments
 
LVL 13

Expert Comment

by:dsmile
ID: 34163077
Well, you have a right approach to set redirect in form_finish.
But it just isn't right.

$form_state['redirect'] = '/path/to/group/page';

or just put this after data processing

drupal_goto('/path/to/group/page');

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(), so if you really want to call it directly, then you have to declare global $node_nid
function mod_form_finish_redirect($form, &$form_state) {
      global $node_nid;
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 34163907
I don't know enough about Drupal to evaluate the question, but there is a Drupal Zone here at EE.  If you ask a moderator, she can add your question to that zone.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now