I'm trying to add multistep form functionality to a node creation form via a form alter. My (abbreviated) code follows:
function mymodule_form_FORM_ID_alter($form, &$form_state)
{
if (!isset($form_state['storage']['step']))
{
$form['actions']['submit']['#submit'][] = 'my_form_submit';
} elseif (isset($form_state['storage']['step']) && $form_state['storage']['step'] == 'step-two')
{
$form['foo'] = array(
'#type' => 'textfield',
'#title' => 'Add foo',
);
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => 'Register',
'#submit' => 'step_two_form_submit',
);
}
}
function my_form_submit($form, &$form_state)
{
if (!isset($form_state['storage']['step']))
{
$form_state['storage']['step'] = 'step-two';
$form_state['rebuild'] = TRUE;
}
//so far so good
}
function step_two_form_submit($form, &$form_state)
{
//This code never runs
drupal_goto('/');
dd('step two ran');
//etc
}
The second step of the form loads as I would expect along with a submit function. The submit callback, however, is never called. Am I making a mistake by nuking the entire $form array? (The $form_state array, which is what I really need to hold onto, remains intact.) I feel like I'm very close but am missing something substantial.