2

I modified my submit handler to be redirected to a "thank you" page after creating some content. So far so good.

But I want to use some data of the node just created, so how can I transfer the $node-data of the just created node to my thank you page?

I created a new block to be shown only on the thank you page and I want to show some $node-data in my block...

function mymodule_block_view($delta = '') {
  switch ($delta) {
    case 'your_block':
      $block['subject'] = 'Share by mail';
      $block['content'] = mymodule_sharebutton();
      break;
  }

  return $block;
}


function mymodule_sharebutton() {
  $output = '<a href="">share</a>';

  return $output;
}

I already tried with passing $node, $form, $form_state,... but with no luck.

  • To make it simpler when you are redirecting perhaps you could slip in node id as a parameter in the url, say /thank-you/3 You could use that to do node_load(nid) or if you think that url will look ugly you could set nid to a session variable before calling drupal_redirect in submit handler and use session variable in thank-you page. – GoodSp33d Feb 19 '13 at 11:26
  • Oh, I like the sound of that. Let me take a look at this. – Michiel Feb 19 '13 at 11:31
  • For some reason, there is no $node variable in my submithandler function... – Michiel Feb 19 '13 at 11:36
  • $form_state contains nid, you need to use that and get $node from node_load() – GoodSp33d Feb 19 '13 at 11:43
  • no $form_state is loaded in my submithandler :( – Michiel Feb 19 '13 at 12:18
0

Use arg(1); - (nid of the current node) in the hook_block_view and pass it in the link

function mymodule_block_view($delta = '') {
  switch ($delta) {
    case 'your_block':
      $nid = arg(1);
      $block['subject'] = 'Share by mail';
      $block['content'] = '<a href="">share?nid='.$nid.'</a>';
      break;
  }
  return $block;
}

Once you do that, you can make your thank_you page react on the nid argument by loading the node:

$node = node_load($nid);

and extracting from it whatever you need

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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