Page redirect after submit form with AJAX


If you use ajax powered form submission then drupal_goto() doesn't work. The only thing that happen is error 200 ;)
To force page redirect we can use helpers provided by CTools (this approach is especially useful when the form is displayed in lightbox):

Get raw version
  1. /**
  2.  * Implements hook_boot()
  3.  */
  4. function mymodule_boot() {
  5. //Save current path
  6. $_SESSION['current_path'] = current_path();
  7. }
  9. function mymodule_custom_ajax_form_submit($form, &$form_state) {
  10. //Close lightbox and redirect to the current page
  11. $path = $_SESSION['current_path'];
  12. ctools_include('ajax');
  13. ctools_add_js('ajax-responder');
  14. $commands[] = ctools_ajax_command_redirect($path);
  15. print ajax_render($commands);
  16. exit;
  17. }


SaHiL's picture

first check if form is successfully submitted or not if yes then
why don't you try using


phponwebsites's picture

Thank you. It is working fine.
But i want to redirect link in new tab. Is it possible?