0

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');
  }
}
2
  • Your question is not very clear. Please give more context and also explain what is not working in your current code.
    – berliner
    Oct 31, 2022 at 8:13
  • @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"
    – Bijan Zand
    Oct 31, 2022 at 8:55

1 Answer 1

1

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');
}
3
  • not work ! drupal_goto('list'); should in "IF"
    – Bijan Zand
    Oct 31, 2022 at 9:07
  • You'd move the if statement above the forach loop then. I've updated my example Oct 31, 2022 at 9:13
  • Thanks man.....
    – Bijan Zand
    Oct 31, 2022 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.