1

For redirecting user to some page after comment submit my below code is working fine :

function my_module_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == "comment_node_link_form") {
      $form['#submit'][] = 'my_module_submit';
  }
}


function my_module_submit($form, &$form_state) {
    $form_state['redirect'] = 'newsroom/en';
}

For Comment links I am sending some query string in comment form URL and want to redirect to user to page after comment according to query string value, How can we fetch the query string value to pass it to redirect on hook_submit

http://www.example.com/comment/reply/208943?destination=newsroom#comment-form

http://www.example.com/comment/reply/208943?destination=sections#comment-form

How can we fetch value of destination and pass it to redirect in hook_submit

Please suggest ! Thanks!

UPDATE : I have tried adding hidden field but not able to access it in hook_submit it shows null :

function my_module_form_alter(&$form, $form_state, $form_id) {
       if ($form_id == "comment_node_link_form") {

           $form['redirect_to'] = array(
             '#type' => 'hidden',
             '#value' => $_GET['destination'],
           );

          $form['#submit'][] = 'my_module_submit';
      }
    }
2
  • Thanks at @Pierre.Vriens , please check answer I posted, this is how I solved this for me. Hope you will found this an interesting approach. And hope I am not moving in any wrong direction.
    – jas
    Jun 17, 2016 at 8:56
  • 1
    Well, that appears to be another solution (haven't tried it, but if it works for you, why not!) Jun 17, 2016 at 9:11

2 Answers 2

1

After More deep debugging I found that action of comment from is set to

comment/reply/nodeid

So with below URL's:

http://www.example.com/comment/reply/208943?destination=newsroom#comment-form

http://www.example.com/comment/reply/208943?destination=sections#comment-form

My query string variable destination is lost or either at form submit it shows null because from moves to action URL where no query string was set.

To solve this I have added query string in action URL which works very well :

function my_module_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == "comment_node_link_form") {
      $form['#action'] = $form['#action'] . '?destination=' . $_GET['destination'];
  }
}

ie: All I have to do is add required query string to $form['#action']

Hope this will help any one who is trying similar solution.

0
function module_menu() {
  $items = array();

  $items['redirect_query_string'] = array(
    'page callback' => 'YourRedirectpagecallbackfunction',
    'access callback' => 'user_access',
    //'access argument' =>  array('Download CSV'),
    'type'  => MENU_CALLBACK,
  );
  return $items;
}

In your form submit write:

if(isset($_GET["redirect_query_string"])){
    return YourRedirectpagecallbackfunction();
  }

function YourRedirectpagecallbackfunction(){
......your redirect url......
}
1
  • "link" is my content type name and I am trying to send argument to hook_submit from my content type comment submit form. Not able to to understand clearly your code, that will be helpful if you can explain little more. Thanks!
    – jas
    Jun 15, 2016 at 11:50

Your Answer

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

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