I am having somewhat of a problem, I am trying to use ajax commands to go to the next case on my form. I dont really understand how to complete this and ive tried numerous ways without any success. Basically what im trying to do in my ajax callback load my preloader function into the #neato_form div's with a 10 second delay and then make it go to case 2 which is step 2 on my form.
Ive included my ajax callback since this is the main problem. Along with my form and submit function in case ive done something wrong there.
Any Suggestions is greatly appreciated.
Ajax commands
function neato_form_ajax_callback($form, &$form_state)
{
$commands = array();
$commands[] = array(
'command' => 'mortgage_response',
'leadstatus' => 'success',
);
$commands[] = ajax_command_replace('#neato_form', preloader());
$commands[] = ajax_command_invoke(NULL, "preloader");
if($commands[0]['leadstatus'] == 'success'){
$commands[] = ajax_command_replace('#neato_form', $form_state['step2']);
}
return array('#type' => 'ajax', '#commands' => $commands);
}
Form and Submit function
function neato_form($form, &$form_state)
{
$form_state['step'] = isset($form_state['step']) ? $form_state['step'] : 1;
$form['#prefix'] = '<div id="neato_form">';
$form['#suffix'] = '</div>';
switch($form_state['step'])
{
// Step 1
case 1:
$default_value = '';
if(isset($form_state['values']['step_1']))
{
$default_value = $form_state['values']['step_1'];
}
elseif(isset($form_state['storage']['step_1']))
{
$default_value = $form_state['storage']['step_1'];
}
$form['step_1'] = array
(
'#type' => 'textfield',
'#title' => t('Step 1'),
'#required' => TRUE,
'#default_value' => $default_value,
);
break;
// Step 2
case 2:
$default_value = '';
if(isset($form_state['values']['step_2']))
{
$default_value = $form_state['values']['step_2'];
}
elseif(isset($form_state['storage']['step_2']))
{
$default_value = $form_state['storage']['step_2'];
}
$form['step_2'] = array
(
'#type' => 'textfield',
'#title' => t('Step 2'),
'#required' => TRUE,
'#default_value' => $default_value,
);
break;
// Step 3
case 3:
$default_value = '';
if(isset($form_state['values']['step_3']))
{
$default_value = $form_state['values']['step_3'];
}
elseif(isset($form_state['storage']['step_3']))
{
$default_value = $form_state['storage']['step_3'];
}
$form['step_3'] = array
(
'#type' => 'textfield',
'#title' => t('Step 3'),
'#required' => TRUE,
'#default_value' => $default_value,
);
break;
}
$form['buttons'] = array
(
'#type' => 'container',
);
$form['buttons']['submit'] = array
(
'#type' => 'submit',
'#value' => t('Submit'),
'#ajax' => array
(
'wrapper' => 'neato_form',
'callback' => 'neato_form_ajax_callback',
),
);
return $form;
}
function neato_form_back_submit($form, &$form_state)
{
$form_state['step']--;
$form_state['rebuild'] = TRUE;
}
function neato_form_submit($form, &$form_state)
{
$step = $form_state['step'];
$form_state['storage']['step_' . $step] = $form_state['values']['step_' . $step];
if(isset($form_state['values']['forward']) && $form_state['values']['op'] == $form_state['values']['forward'])
{
$form_state['step']++;
}
elseif(isset($form_state['values']['submit']) && $form_state['values']['op'] == $form_state['values']['submit'])
{
$items = array($form_state['storage']['step_1'], $form_state['storage']['step_2'], $form_state['storage']['step_3']);
drupal_set_message(t('My !values', array('!values' => theme('item_list', array('items' => $items)))));
$form_state['step'] = 1;
$form_state['storage'] = array();
}
$form_state['rebuild'] = TRUE;
}