Solved

Drupal node creation - back to origin after creation

Posted on 2010-11-18
2
600 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Viewers will learn how to use the Hootsuite Dashboard.

734 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