Solved

Drupal node creation - back to origin after creation

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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

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.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

636 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