Hi All,
I'm having trouble with a multi step form. The form is basically a questionaire with radio buttons (radios) to select the answers (max 3 choices). When the submit button is clicked on the first page, the radio buttons all seem to stay at their default value. I'm using krumo with the Devel module to inspect the variables. Code below...forgive the messy code...still in development!
<?php
/**
* Valid permissions for this module
* @return array An array of valid permissions for the festivalmanager module
*/
function festivalmanager_perm() {
return array('access festivalmanager content');
}
//Admin page for Festival Manager module
function festivalmanager_menu() {
$items = array();
$items['festivalmanager'] = array(
'title' => 'Virtual Assistant',
'page callback' => 'festivalmanager_page',
'access arguments' => array('access festivalmanager content'),
'type' => MENU_CALLBACK
);
return $items;
}
function festivalmanager_page() {
return drupal_get_form('festivalmanager_myform');
}
function festivalmanager_myform(&$form_state) {
if (empty($form_state['storage']['step'])) {
// we are coming in without a step, so default to step 1
$form_state['storage']['step'] = 1;
}
switch ($form_state['storage']['step']) {
case 1:
$form['posting_settings']['question 1'] = array(
'#type' => 'radios',
'#title' => t('How would you rate your current hearing difficulties in all situations?'),
'#default_value' => variable_get('question 1', 1),
'#options' => array(0=>'Mild', 1=>'Moderate', 2=>'Severe'),
);
$form['posting_settings']['question 2'] = array(
'#type' => 'radios',
'#title' => t('How would your friends & family rate your hearing difficulties?'),
'#default_value' => variable_get('question 2', 1),
'#options' => array(t('Mild'), t('Moderate'), t('Severe')),
);
$form['posting_settings']['question 3'] = array(
'#type' => 'radios',
'#title' => t('Do you need people to repeat themselves?'),
'#default_value' => variable_get('question 3', 1),
'#options' => array(t('Never'), t('Sometimes'), t('Often')),
);
$form['posting_settings']['question 4'] = array(
'#type' => 'radios',
'#title' => t('Do you feel people speak to fast?'),
'#default_value' => variable_get('question 4', 1),
'#options' => array(t('Never'), t('Sometimes'), t('Often')),
);
$form['posting_settings']['question 5'] = array(
'#type' => 'radios',
'#title' => t('Do you feel people do not speak clearly or mumble?'),
'#default_value' => variable_get('question 5', 1),
'#options' => array(t('Never'), t('Sometimes'), t('Often')),
);
$form['posting_settings']['question 6'] = array(
'#type' => 'radios',
'#title' => t('Do you have difficulties hearing someone from another room?'),
'#default_value' => variable_get('question 6', 1),
'#options' => array(t('Never'), t('Sometimes'), t('Often')),
);
$form['posting_settings']['question 7'] = array(
'#type' => 'radios',
'#title' => t('Do you have the TV turned up louder than any friends or family?'),
'#default_value' => variable_get('question 7', 1),
'#options' => array(t('Never'), t('Sometimes'), t('Often')),
);
$form['posting_settings']['question 8'] = array(
'#type' => 'radios',
'#title' => t('Can you hear conversation in one to one situations?'),
'#default_value' => variable_get('question 8', 1),
'#options' => array(t('Never'), t('Sometimes'), t('Often')),
);
break;
case 2:
$form['posting_settings']['question 1-2'] = array(
'#type' => 'radios',
'#title' => t('Do you attend meetings (including church services)?'),
'#default_value' => variable_get('question 1-2', 1),
'#options' => array(t('Rare'), t('Sometimes'), t('Often')),
);
$form['posting_settings']['question 2-2'] = array(
'#type' => 'radios',
'#title' => t('Do you attend family gatherings in a group?'),
'#default_value' => variable_get('question 2-2', 1),
'#options' => array(t('Rare'), t('Sometimes'), t('Often')),
);
$form['posting_settings']['question 3-2'] = array(
'#type' => 'radios',
'#title' => t('Do you attend gatherings with friends?'),
'#default_value' => variable_get('question 3-2', 1),
'#options' => array(t('Rare'), t('Sometimes'), t('Often')),
);
$form['posting_settings']['question 4-2'] = array(
'#type' => 'radios',
'#title' => t('Do you visit clubs?'),
'#default_value' => variable_get('question 4-2', 1),
'#options' => array(t('Rare'), t('Sometimes'), t('Often')),
);
$form['posting_settings']['question 5-2'] = array(
'#type' => 'radios',
'#title' => t('Do you visit shops?'),
'#default_value' => variable_get('question 5-2', 1),
'#options' => array(t('Rare'), t('Sometimes'), t('Often')),
);
$form['posting_settings']['question 6-2'] = array(
'#type' => 'radios',
'#title' => t('Do you visit cafes or restaurants?'),
'#default_value' => variable_get('question 6-2', 1),
'#options' => array(t('Rare'), t('Sometimes'), t('Often')),
);
$form['posting_settings']['question 7-2'] = array(
'#type' => 'radios',
'#title' => t('Do you drive in the car with other people?'),
'#default_value' => variable_get('question 7-2', 1),
'#options' => array(t('Rare'), t('Sometimes'), t('Often')),
);
break;
case 3:
$form['posting_settings']['question 1-3'] = array(
'#type' => 'radios',
'#title' => t('Type of Device - Answer one of the following questions'),
'#default_value' => variable_get('question 1-3', 1),
'#options' => array(t('I want the most natural sounding device possible'), t('I want the best device at helping me in background noise situations')),
'#attributes' => array('class' => t('radio_block')),
);
$form['posting_settings']['question 2-3'] = array(
'#type' => 'radios',
'#title' => t('Personalised preferance - Answer one of the following questions'),
'#default_value' => variable_get('question 2-3', 1),
'#options' => array(t('I have a budget limit and need the best bang for buck!'), t('I need a hearing aid that has good moisture resistance'), t('I want the smallest device possible')),
'#attributes' => array('class' => t('radio_block')),
);
break;
}
if ($form_state['storage']['step'] > 1) {
$form['previous'] = array(
'#type' => 'submit',
'#value' => '<< Previous'
);
}
//show next button all the time
$form['next'] = array(
'#type' => 'submit',
'#value' => 'Next >>'
);return $form;
}
function festivalmanager_myform_submit($form, &$form_state) {
//save the values for the current step into the storage array
$form_state['storage']['values'][$form_state['storage']['step']] = $form_state['values'];
//$x=1;
drupal_set_message(t($form_state['posting_settings']['question 2']['#options']));
// if ($form_state['values']['Question 1']['#value'] == "Moderate"){
//$x=$x+1;
//drupal_set_message(t($x));}
// check the button that was clicked and action the step change
if ($form_state['clicked_button']['#id']=='edit-previous') {
$form_state['storage']['step']--;
} elseif ($form_state['clicked_button']['#id']=='edit-next') {
$form_state['storage']['step']++;
}
krumo($form_state['storage']['values']);
//tell Drupal we are redrawing the same form
$form_state['rebuild'] = TRUE;
drupal_set_message(t('Your form has been saved.'));
}

Comments
Solved
Ok...solved by using
$form_state['clicked_button']['#post']
instead of
$form_state['values']
in the submit function
not sure why but it works for me!...