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(&$form, &$form_state, $form_id) {
dsm($form);
dsm($form_state);
dsm($form_id);
if(strpos(current_path(), 'print') !== false && $form['#node']->type == 'genericforms') {
$form['actions']['submit'] = array (
'#type' => 'submit',
'#value' => 'submit',
'#submit' => 'he_helper_custom_redirect'
);
}
}
function he_helper_custom_redirect($form, &$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(&$form, &$form_state, $form_id) {
// dsm($form);
// dsm($form_state);
// dsm($form_id);
if(strpos(current_path(), 'print') !== false && $form['#node']->type == 'genericforms') {
// $form['#after_build'][] = 'he_helper_after_build';
$form['actions']['submit'] = array (
'#type' => 'submit',
'#value' => '2hello',
'#submit' => array('_he_helper_custom_submit'),
);
}
}
function _he_helper_custom_submit(&$form, &$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(&$form, &$form_state, $form_id) {
// dsm($form);
// dsm($form_state);
// dsm($form_id);
if(strpos(current_path(), 'print') !== false && $form['#node']->type == 'genericforms') {
$form['#after_build'][] = 'he_helper_after_build';
}
}
function he_helper_after_build(&$form, &$form_state) {
$form['actions']['submit'] = array (
'#type' => 'submit',
'#value' => '2hello',
'#submit' => array('_he_helper_custom_submit'),
);
return $form;
}
function _he_helper_custom_submit(&$form, &$form_state) {
print 'hello';
dsm('hello');
$form_state['redirect'] = 'print';
$form_state['rebuild'] = TRUE;
}