Redirect to custom page after creating a node with nid as a parameter

Alexzander - December 25, 2008 - 22:57

Hi everybody,

I spent huge amount of time searching net to find best solution. Finally, after understanding node.module, I`ve found out that form_submit return value could be used for redirection.

So, what I want to do is to redirect a user to custom page after node creation with nid as a parameter.
To do it, you should:
1. Create a wrapper submission function, which will call default one (node_form_submit), retrieve nid of created node and redirect to your_custom_page.

<?php
function your_module_redirect_submit($form_id, $form_values)
{   
   
$node_url = node_form_submit($form_id, $form_values);
   
dpr("Node URL:".$node_url);
    return
'your_custom_page/'.str_replace('node/','',$node_url);
}
?>

2. Replace default one with yours on form alter for needed_node_type.

<?php
function your_module_form_alter($form_id, &$form)
{
    if (
$form_id == 'needed_node_type_node_form')
    {                               
        unset(
$form['#submit']['node_form_submit']);   
       
$form['#submit']['your_module_redirect_submit'] = array();                       
    }
}
?>

Hope it will help somebody.

You can do it

ckng - December 26, 2008 - 16:46

You can do it with

<?php
function yourmodule_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if (
$node->type == 'needed_node_type') {
    if (
$op == 'insert') {
     
drupal_goto('your_url/' . $node->nid);
    }
  }
}
?>

--
CK Ng | myFineJob.com

Read The Fine Manual :~)

simsim - December 27, 2008 - 05:53

You could simply use the Form API's #redirect property.
________________________
"Creativity is knowing how to hide your resources" - Albert Einstein.

He needs the nid, I don't

ckng - December 27, 2008 - 17:30

He needs the nid, I don't think you can get it in form_alter hence #redirect will not work.

--
CK Ng | myFineJob.com

Rules module

ibandyop - February 2, 2009 - 02:29

http://drupal.org/project/rules You can use Tokens in URL

 
 

Drupal is a registered trademark of Dries Buytaert.