Hey,
I tried look for a module or tweak for that with no luck…
How I can change the default setting for crating content that when I click "save" it will stay on the same page (the add form page) instead of going the new node page.
Same thing for editing an existing node.
Any idea?

Thanks,
Shay

Comments

matkeane’s picture

Hi,

Sounds like http://drupal.org/project/addanother or http://drupal.org/project/submitagain would help with the first situation, and http://drupal.org/project/save_edit with the second.

shaynl’s picture

It's working great when adding a new node with submitagain but not when edit a node… save_edit not doing the job as I need the users to stay on the same page (the add new node page). The user can see the new nods in a block on that page (using views). Is it possible to edit node within a block view?
p.s
This is a print screen of my "add new node page":
http://www.mypicx.com/uploadimg/604093315_08192009_1.jpg

sapark’s picture

You could write your own module! Here's how -- haven't tried this, but might work and you could tweak it:

this goes in a file called redirectedit.module (or whatever you want to call it) (put the php tag in the beginning --don't need ?> in the ending, it just shows here to get the code formatted in color, and it's not needed for coding best practice where it has a risk of messing your web site page up for some reason if left in there.)

(switch out mycontenttype for your content type)

I'm going to use hook_nodeapi because it does a lot of node things, see here http://api.drupal.org/api/function/hook_nodeapi/6.

// Implementation of hook_nodeapi. Redirect user to add new node after saving a new node or updating an existing node.

function redirectedit_nodeapi ($node, $op, $a3 = NULL, $a4 = NULL) {
  if ($node->type == "mycontenttype") {
    switch ($op) {
      // Saving/Inserting a new node into database.
      case "insert":
        // Redirect to new node form at example.com/node/add/mycontenttype.
        $_REQUEST['destination'] = "node/add/mycontenttype";
      break;
      // Updating an existing node in database.
      case "update":
        // Redirect to new node form at example.com/node/add/mycontenttype.
        $_REQUEST['destination'] = "node/add/mycontenttype";

        // OPTIONALLY Redirect back to edit page.
        // $nid is the second argument in URL, e.g., example.com/node/100/edit
        // node is arg(0), 100 is arg(1), and edit is arg(2)
        //$nid = arg(1);
        // Redirect back to example.com/node/100/edit
        //$_REQUEST['destination'] = "node/" . $nid . "/edit";

      break;
    }
  }
}

this goes in a file called redirectedit.info
; $Id$
name = Redirect to edit
description = Redirect user to add new node after saving a new node or updating an existing node.
core = 6.x
version = 6.x-1.0

those files go in a folder called sites/all/modules/redirectedit

there you have your new module! I think this will work, not sure. Also there's a http://drupal.org/project/formblock module to put forms in blocks. Hope that helps.

miaoulafrite’s picture

thanks,
in case of a redirection to the edition form, redirection should be:

$_REQUEST['destination'] = 'node/' . $node->nid . '/edit';
shaynl’s picture

I tried it now and it works like a charm!
How I can add more content types to this script?

sapark’s picture

Excellent!

copy the if block and paste beneath the first if block (without opening and closing php tags) to look like this

if ($node->type == "mycontenttype") {
  switch ($op) {
    // Saving/Inserting a new node into database.
    case "insert":
      // Redirect to new node form at example.com/node/add/mycontenttype.
      $_REQUEST['destination'] = "node/add/mycontenttype";
    break;
    // Updating an existing node in database.
    case "update":
      // Redirect to new node form at example.com/node/add/mycontenttype.
      $_REQUEST['destination'] = "node/add/mycontenttype";

      // OPTIONALLY Redirect back to edit page.
      // $nid is the second argument in URL, e.g., example.com/node/100/edit
      // node is arg(0), 100 is arg(1), and edit is arg(2)
      //$nid = arg(1);
      // Redirect back to example.com/node/100/edit
      //$_REQUEST['destination'] = "node/" . $nid . "/edit";

    break;
  }
}

if ($node->type == "mycontenttype") {
  switch ($op) {
    // Saving/Inserting a new node into database.
    case "insert":
      // Redirect to new node form at example.com/node/add/mycontenttype.
      $_REQUEST['destination'] = "node/add/mycontenttype";
    break;
    // Updating an existing node in database.
    case "update":
      // Redirect to new node form at example.com/node/add/mycontenttype.
      $_REQUEST['destination'] = "node/add/mycontenttype";

      // OPTIONALLY Redirect back to edit page.
      // $nid is the second argument in URL, e.g., example.com/node/100/edit
      // node is arg(0), 100 is arg(1), and edit is arg(2)
      //$nid = arg(1);
      // Redirect back to example.com/node/100/edit
      //$_REQUEST['destination'] = "node/" . $nid . "/edit";

    break;
  }
}

and switch out mycontentype for myothercontentype, repeat the copy for as many content types you need.

Hope that helps.

Matthew OMalley’s picture

You only need to add new content types into the "if" line at the beginning.

<?php
if (($node->type == "mycontenttype") || ($node->type == "myothercontenttype")) {
  switch ($op) {
    // Saving/Inserting a new node into database.
    case "insert":
      // Redirect to new node form at example.com/node/add/mycontenttypes.
      $_REQUEST['destination'] = "node/add/".$node->type;
    break;
    // Updating an existing node in database.
    case "update":
      // Redirect to new node form at example.com/node/add/mycontenttypes.
      $_REQUEST['destination'] = "node/add/".$node->type;

      // OPTIONALLY Redirect back to edit page.
      // $nid is the second argument in URL, e.g., example.com/node/100/edit
      // node is arg(0), 100 is arg(1), and edit is arg(2)
      //$nid = arg(1);
      // Redirect back to example.com/node/100/edit
      //$_REQUEST['destination'] = "node/" . $nid . "/edit";

    break;
  }
}
?>
sapark’s picture

Thanks!

enboig’s picture

I have tried in D6 and it is not working; any hint?

function cc_assentaments_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if (($node->type=='cc_linia') && ($op=='insert')) {
$_REQUEST['destination'] = "cc_linia/".$node->nid.'/desglos';
}
}

La vida és una taronja, què esperes per exprimir-la?

enboig’s picture

I forgot a:

form['redirect']=false; 

Inside the code. Now it works as a charm. At last I put the code inside hook_insert in order do avoid adding a hook_nodeapi.

La vida és una taronja, què esperes per exprimir-la?

ashhishhh’s picture

Thanks Matthew :)

ˇh2nk’s picture

hi i also created that little module. no errors all fine but the redirection part dosent work.
to: enboig can you post your script here? how you implemented that code what you posted ?

Thanks.

rukaya’s picture

I created a new submit button and my own custom submit, like this:

in hook_form_alter:

	$form['buttons']['savereturn'] = Array (
				'#type' => 'submit',
				'#value' => t('<  Save and return to Task Manager'),
				'#weight' => 4,
				'#submit' => Array('_workflow_return_to_task_manager_submit', 'node_form_submit'),
				'#attributes' => array('class' => 'form-submit-return'),
	);

Custom function:

function _workflow_save_and_return_to_task_manager_submit($form, &$form_state) {
	drupal_goto('/admin/content/workflow');
}
enboig’s picture

I would avoid using drupal_gioto() as much as I can. It stops drupal execution, so some hooks may be ignored.

La vida és una taronja, què esperes per exprimir-la?

rta’s picture

use this in D7:

function module_node_insert ($node) {
  if ($node->type == "mycontenttype") {
    drupal_goto('node/add/mycontenttype');
  }
}
Syd Barrett’s picture

Why don't you try with Rules module.

After saving new content -> Page redirect and you can use the Replacement patterns