Score:0

Redirect page after all nodes save

in flag

I am trying to write a custom module to save special nodes. With my code after first node save, page redirect and other not affected.

I need after all nodes_save redirect to list.

$nidew = [12,34,55,12,66,63];
foreach ($nidew as $nodeuniqe) {
  if (isset($_POST['submit'])) {
    $node = node_load($nodeuniqe); 
    node_save($node);
    drupal_goto('list');
  }
}
berliner avatar
bd flag
Your question is not very clear. Please give more context and also explain what is not working in your current code.
Bijan Zand avatar
in flag
@berliner my code just first node saved and go redirect before all node save, i want node_save all nodes in $nodeuniqe after that redirect to "list"
Score:1
aq flag

Sounds like a simple PHP issue and you wnt to take the redirect command out of the foreach loop e.g.:

$nidew = [12,34,55,12,66,63];
if (isset($_POST['submit'])) {
  foreach ($nidew as $nodeuniqe) {
    $node = node_load($nodeuniqe); 
    node_save($node);
  }
  drupal_goto('list');
}
Bijan Zand avatar
in flag
not work ! drupal_goto('list'); should in "IF"
unusedspoon avatar
aq flag
You'd move the if statement above the forach loop then. I've updated my example
Bijan Zand avatar
in flag
Thanks man.....
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.