One Multistep (onemultistep)
Component ID
Component name
Component type
Maintenance status
Development status
Component security advisory coverage
Component created
Component changed
Component body
One Multistep module is a tool for creating form builder functions using the Form API. By defining dependencies between form elements, One Multistep creates the #ajax to respond to changes in js enabled clients, and transform each step on a sub multi-step form for non js enabled clients.
What it does
Creates a multistep form (if you define any steps) and for each step:
js enabled - Updates the dependent elements using AJAX.
no js - Converts the step on a sub multi-step form based on the dependencies.
How it works
- Include a call to
onemultistep_start($form, $form_state)on your form builder function. - Use
onemultistep_set_step($form, 'step_name', $setting)to define steps. - Assign step to form elements with
'#step' => 'step_name' - Include a call to
onemultistep_depends($form, 'element', array('element1', ...))on your form builder function for each form element that depends on others.
Check the Configuration section and the example that goes with the module for more.
How it's done
One Multistep module uses a #process and a #after_build functions for the form, and attaches 'onemultistep.js' and 'onemultistep.css'.
Example
function onemultistep_example_dependent_dropdown($form, &$form_state) {
onemultistep_start($form, $form_state);
$options_first = _onemultistep_example_get_first_dropdown_options();
$element = array(
'#type' => 'select',
'#title' => 'Instrument Type',
'#options' => $options_first,
'#empty_value' => '',
'#required' => TRUE,
);
$selected = onemultistep_builder_value($form_state, 'dropdown_first', $element);
$element['#default_value'] = $selected;
$form['dropdown_first'] = $element;
$element = array(
'#type' => 'select',
'#title' => (empty($selected) ? '' : $options_first[$selected] . ' ') . t('Instruments'),
'#options' => _onemultistep_example_get_second_dropdown_options($selected),
'#empty_value' => '',
'#required' => TRUE,
);
$value = onemultistep_builder_value($form_state, 'dropdown_second', $element);
$element['#default_value'] = $value;
$form['dropdown_second'] = $element;
if (empty($selected)) {
$form['dropdown_second']['#description'] = t('You must make your choice on the first dropdown before changing this second one.');
}
onemultistep_depends($form, 'dropdown_second', array('dropdown_first'));
onemultistep_set_button($form, 'submit',
array(
'#type' => 'submit',
'#value' => t('OK'),
)
);
return $form;
}
function _onemultistep_example_get_first_dropdown_options() {
return drupal_map_assoc(array(t('String'), t('Woodwind'), t('Brass'), t('Percussion')));
}
function _onemultistep_example_get_second_dropdown_options($key = '') {
$options = array(
t('String') => drupal_map_assoc(array(t('Violin'), t('Viola'), t('Cello'), t('Double Bass'))),
t('Woodwind') => drupal_map_assoc(array(t('Flute'), t('Clarinet'), t('Oboe'), t('Bassoon'))),
t('Brass') => drupal_map_assoc(array(t('Trumpet'), t('Trombone'), t('French Horn'), t('Euphonium'))),
t('Percussion') => drupal_map_assoc(array(t('Bass Drum'), t('Timpani'), t('Snare Drum'), t('Tambourine'))),
);
if (isset($options[$key])) {
return $options[$key];
}
else {
return array();
}
}
function onemultistep_example_dependent_dropdown_submit($form, &$form_state) {
// Now handle the case of the next, previous, and submit buttons.
switch ($form_state['triggering_element']['#value']) {
case t('OK'): // Submit: We're done.
drupal_set_message(t('Your values have been submitted. dropdown_first=@first, dropdown_second=@second', array('@first' => $form_state['values']['dropdown_first'], '@second' => $form_state['values']['dropdown_second'])));
break;
}
}
Configuration
To be done...
Related projects
Chaos tool suite (ctools)
Field Group Ajaxified Multipage
Form Builder
Multiple Entity Form
Subform
Multiple forms
Entityforms
Configuration builder
Field group
Multistep
Modal forms (with ctools)
Context Form Alteration
OO Wizard
Code generator
Hub
Form API Helper
