I am new to Drupal development and I stuck on a problem. I have got a form which I append to a node. The custom submit method is called correctly, but my redirect does not work. When I press the button I got redirected to the form. Thank you very much in advance

    function ticketGenerator_node_view($node, $view_mode) {
    $nodetype = node_type_get_type($node);
    $nodetype = $nodetype->type;
    if ($view_mode == 'full' && node_is_page($node) && $nodetype=='event') {
    $node->content['buttonKaufentest'] = drupal_get_form('ticketGenerator_generateform',$node);
    return $node;


    function ticketGenerator_generateform($form, &$form_state,$node){
    $form = array();
    $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    $form['submit'] = array(
    '#type' => 'submit' ,
    '#value' => 'buttonalter',
    '#submit' => array('ticketGenerator_list_submit')
 return $form;


   function ticketGenerator_list_submit($form,$form_state){
   drupal_set_message('custom submit has been invoked');
   $form_state['redirect'] = 'www.google.de';
  • As nearly as I can tell, your custom submit function does nothing but set the message and the value of $form_state['redirect']. It does not actually submit the form. You do not get redirected back to the form. You never left it. All that happened is your browser refreshed itself with the message.
    – Triskelion
    Mar 23 '13 at 22:22
  • If that is all you want to have happen, add the line drupal_redirect_form($form_state); after setting the redirect (and after changing the parameter to pass by reference) and try it again.
    – Triskelion
    Mar 23 '13 at 22:28

You need to pass $form_state in by reference, or the change won't be persisted outside of the function scope:

function ticketGenerator_list_submit($form, &$form_state) {
  • Ahh damn! How couldnt I see it myself?Thank you very much! That fixed it. Mar 23 '13 at 22:28
  • Thanks. I was working on old code and didn't spot the missing &. Oct 28 '15 at 1:14

In my case for Drupal 7 forms. I was setting $form_state[redirect] in the submit handler function and I also did a print_r() to make sure it was there and it was. But it wouldn't redirect. I had to unset the following variables in order for it to work:


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.