Solved

Drupal node creation - back to origin after creation

Posted on 2010-11-18
2
598 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 109

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Logic behind "best rated" calculation 11 30
Get a subdirectory name from a url 5 27
What is wrong with this PDO Delete Query? 2 17
Need to remove %20 from url in get 17 36
Let’s list some of the technologies that enable smooth teleworking. 
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

839 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