By mrodgers on
I am trying to create multi step form that submits a node with 5.0. An example of the code below.
Two problems.
1. The form presents me with the Node "Preview" or "Submit" buttons rather than the "Next Step Button"
2. As a result of the above the node is being created before gathering additional data in step two.
Thanks
function example_form(&$node, $form_values = NULL) {
if (!isset($form_values)) {
$step = 1;
}
else {
$step = $form_values['step'] + 1;
}
$form['step'] = array('#type' => 'hidden','#value' => $step,);
switch ($step) {
case 1:
$form[test] = array('#type' => 'checkbox', '#title' => t('Select Value'));
break;
case 2:
$test = $form_values['test'];
$form[test] = array('#type' => 'checkbox','#title' => t('Select Value'));
}
// This part is important!
$form['#multistep'] = TRUE;
$form['#redirect'] = FALSE;
// Different Submit buttonsfor different steps of the form
If ($step == '1')
{$form['submit'] = array('#type' => 'submit', '#value' => t('Next'));}
else
{$form['submit'] = array('#type' => 'submit','#value' => t('Step 3 - Almost Done'));};
return $form;
}
Comments
I have the same issue
I discovered $form_values was absent. Been trying to back track as to why it is missing, but no solution yet. I also put the buttons inside each case as there is no 'back' when case 1: and on the last page the 'next' becomes 'submit' or 'finish'. I use a debug like
Of course this may or may not be your problem! I used 'func_get_args' to see what params there were and I get the node plus three empty, which ties up with a 'node_invoke' in node.module.
The removal of 'Preview' is a separate topic and there is a solution on this forum if you search for 'remove preview'. Basically you use a form-alter hook to unset it.
You also need to put a test in your submit so that it only updates the db when $step == 2.
Validate might need similar treatment.
Paul
www.scryptik.com - Javascript editor with syntax error checking
www.purpleoar.co.nz/scryptik - Javascript editor with syntax error checking
www.purpleoar.co.nz - Web development, Drupal consultancy