The Chaos tools form wizard is a very nice piece of code but I had the need to extend it by adding a control button - which turned out to be a lot easier than you might think.
Adding the control button itself was simple enough:
$form['buttons']['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#next' => $current_step,
'#wizard type' => 'update',
'#weight' => -500,
);
But notice I have given this button a wizard type of "update" (as opposed to 'next', 'cancel' or 'finish').
Now you can either add a new line to your $form_info array:
$form_info['update callback'] = 'mywizard_update';
Or not, in which case the function $form_info['id'] . '_update' will be called.
Your function will get called when this button is clicked with &$form_state as the parameter. Cool.
As an additional point, I'm using 'update' here which means that I do want to validate the form entries and save the values. However by adding these element attributes:
'#limit_validation_errors' => array(),
'#submit' => array('ctools_wizard_submit'),
You can prevent all validation and ensure the proper Chaos tools wizard function is executed.
No comments:
Post a Comment