I use Ctools Modal to show the login form to users in an overlay. If a user enters right data then he is logged in and the page is refreshed.
The code:
function login_overlay_menu() {
$items['login-overlay'] = array(
'title' => t('Sign in'),
'page callback' => 'login_overlay_callback',
'page arguments' => array(),
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
return $items;
}
function login_overlay_callback($js = TRUE){
ctools_include('modal');
ctools_include('ajax');
$form_state = array(
'ajax' => TRUE,
);
$output = ctools_modal_form_wrapper('login_overlay_form', $form_state);
if (isset($_GET['destination'])) {
$output[] = login_overlay_redirect($_GET['destination']);
}
else {
$output[] = ctools_ajax_command_reload();
}
print ajax_render($output);
}
function login_overlay_redirect($path) {
global $user;
if (isset($languages[$user->language])) {
$options = array('language' => $languages[$user->language]);
}
return ctools_ajax_command_redirect($path, 0, $options);
}
The Catch:
It works well for right data entered at first attempt. However, if a validation fails, then the form is rebuild inside the overlay. and then if the user submits the form, he is logged in but the page is not refreshed (which is very important).
When I debugged the JS code I found that the value of Drupal.settings.ajaxPageState.js
changing is the only difference before and after the validation fail.
Before: it is an object containing list of all js files loaded for that page.
After: it is an empty array. (Array[0])
.
THE QUESTION: I am not even sure if this is what causing the error. However if it is, then what may be causing this to happen? OR if not then what may be causing the page refresh to fail?
Drupal.settings.ajaxPageState.js
to an empty array. Thanks for suggestion anyway.login_overlay_redirect
andctools_ajax_command_reload
) are in same response withlogin_overlay_form
displayed in modal? This means automatic page refresh after loading the modal. I think redirecting/refreshing should be as a result of submit handler forlogin_overlay_form
.