Webform custom submit handler rebuild I am acutally trying to build a custom webform submit handler to force the form to be rebuilded. I know that this is possible with the integrated webform settings, but I need to do it programmatically.

Here is what my code looks like at the moment:

function he_helper_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    dsm($form);
    dsm($form_state);
    dsm($form_id);

    if(strpos(current_path(), 'print') !== false &amp;&amp; $form['#node']-&gt;type == 'genericforms') {
        $form['actions']['submit'] = array (
            '#type' =&gt; 'submit',
            '#value' =&gt; 'submit',
            '#submit' =&gt; 'he_helper_custom_redirect'
        );
    }
}


function he_helper_custom_redirect($form, &amp;$form_state) {

    $form_state['rebuild'] = TRUE;

}


The problem now is, that the rebuild works as expected, but the form data does not get submitted. I tried it with $form_state['redirect'] as well, but ran into the same problem.

Anyone got an idea how to solve that?

UPDATE:

function he_helper_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  // dsm($form);
  // dsm($form_state);
  // dsm($form_id);
  if(strpos(current_path(), 'print') !== false &amp;&amp; $form['#node']-&gt;type == 'genericforms') {
    // $form['#after_build'][] = 'he_helper_after_build';
    $form['actions']['submit'] = array (
      '#type' =&gt; 'submit',
      '#value' =&gt; '2hello',
      '#submit' =&gt; array('_he_helper_custom_submit'),
    );
  }
}

function _he_helper_custom_submit(&amp;$form, &amp;$form_state) {
  $form_state['redirect'] = 'print';
  $form_state['rebuild'] = TRUE;
}


This is what my code now actualy looks like. The redirect now works fine, but the data wont get submitted. I tried the after_build function as well, but when i am using this, even my redirect wont work. This is what my code looked like with the after_build

function he_helper_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  // dsm($form);
  // dsm($form_state);
  // dsm($form_id);
  if(strpos(current_path(), 'print') !== false &amp;&amp; $form['#node']-&gt;type == 'genericforms') {
    $form['#after_build'][] = 'he_helper_after_build';
  }
}


function he_helper_after_build(&amp;$form, &amp;$form_state) {
  $form['actions']['submit'] = array (
    '#type' =&gt; 'submit',
    '#value' =&gt; '2hello',
    '#submit' =&gt; array('_he_helper_custom_submit'),
  );
  return $form;
}

function _he_helper_custom_submit(&amp;$form, &amp;$form_state) {
  print 'hello';
  dsm('hello');
  $form_state['redirect'] = 'print';
  $form_state['rebuild'] = TRUE;
}
I think I've just used $form_state['redirect'] in the submit handler in the past.

However I'm not sure what order your submit handlers are firing in, maybe it would work if you added the after_build function to the form array as opposed to the button array. (If your custom submit handler is firing first then your redirect could get overwritten.)

E.g: $form['#submit'][] = 'he_helper_custom_redirect';


If that doesn't work then this post suggests using rebuild with redirect:

$form_state['redirect'] = 'where-do-you-want-to-go-today';
$form_state['rebuild'] = TRUE;


This code shows how to add a new custom submit handler without overwriting the original one:

function he_helper_after_build(&amp;$form, &amp;$form_state) {

  // add to the existing submit array to not override the default submit handler
  $form['actions']['submit']['#submit'][] = '_he_helper_custom_submit';

  // change the button text
  $form['actions']['submit']['#value'] = '2hello';

  return $form;
}