Posted by duckzland on June 11, 2010 at 9:05pm
I'm building a multistep form with ahah, on the first step, when ahah is called from a button the ahah is working and the form progress to step two, on the step two when the final button is clicked then the ahah is working and reverting back to step one.
the problem is after the new step one is build, the ahah button to get to new step two is broken and doing a full page refresh, but then when the page refreshed and come to step two, ahah is working again when we click the button to call another new step one.
the form code :
<?php
function drupie_multimedia_create_album_form($form_state) {
$form = array(
'#tree' => true,
);
$form['album'] = array(
'#type' => 'fieldset',
'#prefix' => '<div id="album">',
'#suffix' => '</div>',
'#collapsible' => false,
'#collapsed' => false,
'#tree' => true,
);
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['album']['album_type'] = array(
'#type' => 'select',
'#title' => t('Album Type'),
'#description' => t('What is your album type going to be?'),
'#options' => array('image_album' => t('Images album'), 'video_album' => t('Video album'), 'audio_album' => t('Audio album')),
'#required' => TRUE,
);
$form['album']['next'] = array(
'#type' => 'submit',
'#name' => 'next-2',
'#value' => t('Next'),
'#submit' => array('next_page'),
'#ahah' => array(
'event' => 'click',
'path' => 'multimedia/create-album/next',
'wrapper' => 'album',
'method' => 'replace',
'effect' => 'slide',
'progress' => array('type' => 'bar', 'message' => 'Please wait...'),
),
'#attributes' => array(
'class' => 'edit-ahah',
),
);
break;
case 2:
$form['album']['header'] = array(
'#value' => $form_state['storage']['new_nid'],
'#theme' => 'create_album_top_two',
);
$form['album']['submit'] = array(
'#type' => 'submit',
'#name' => 'finish',
'#value' => t('Save'),
'#prefix' => '<div class="multimedia-album-information"><p class="album-desc">' . t('Don\'t forget to save your upload by clicking the save button') . '</p>', // todo add this in the setting form
'#suffix' => '</div>',
'#submit' => array('save_content'),
'#ahah' => array(
'event' => 'click',
'path' => 'multimedia/create-album/finish',
'wrapper' => 'album',
'method' => 'replace',
'effect' => 'slide',
'progress' => array('type' => 'bar', 'message' => 'Please wait...'), // to do add small progress bar
),
'#attributes' => array(
'class' => 'edit-submit',
),
);
break;
}
return $form;
}
?>the submit code:
<?php
function save_content($form, &$form_state) {
unset($form_state['submit_handlers']);
form_execute_handlers('submit', $form, $form_state);
$form_state['storage']['step'] = '1';
$form_state['values']['album'] = '';
$form_state['storage']['album'] = '';
$form_state['rebuild'] = TRUE;
}
function next_page($form, &$form_state) {
$form_state['storage']['step'] = 2;
$form_state['storage']['data'] = $form_state['values'];
$form_state['rebuild'] = TRUE;
}
?>the js function :
<?php
function multimedia_js() {
$form_state = array('storage' => NULL, 'submitted' => FALSE);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form['#post'] = $_POST;
$form['#redirect'] = FALSE;
$form['#programmed'] = FALSE;
$form_state['post'] = $_POST;
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
$form_portion = $form['album'];
unset($form_portion['#prefix'], $form_portion['#suffix']); // Prevent duplicate wrappers.
$javascript = drupal_add_js(NULL, NULL);
$output_js = isset($javascript['setting']) ? '<script type="text/javascript">jQuery.extend(Drupal.settings, '. drupal_to_js(call_user_func_array('array_merge_recursive', $javascript['setting'])) .');</script>' : '';
$output = theme('status_messages') . drupal_render($form_portion);
$output .= $output_js;
drupal_json(array('status' => TRUE, 'data' => $output));
?>
}Anyone know what may be the cause of this?
Thanks in advance
Comments
Fix this myself, seems that
Fix this myself, seems that ahah fails to register the event bubbling, by using the quicktabs_ahah.js the problem fixed.
--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com
skype id : duckzland