ajax_register.pages.inc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * @file
  4. * Page callback for ajax links.
  5. */
  6. /**
  7. * Returns USER LOGIN / REGITER / PASSWORD form.
  8. * @param $form_type
  9. * Type of form that should be loaded.
  10. * @param $js
  11. * Show whether user has enabled js in his browser.
  12. */
  13. function ajax_register_page_callback($form_type, $js) {
  14. // Check whether js is enabled.
  15. if ($js) {
  16. // Include ctools modal plugin.
  17. ctools_include('modal');
  18. $form_state = array('ajax' => TRUE);
  19. // Array with ajax response.
  20. $commands = array();
  21. if ($form_type == 'password') {
  22. // Show USER PASSWORD form.
  23. module_load_include('pages.inc', 'user');
  24. $form_state['title'] = t('Request new password');
  25. $commands = ctools_modal_form_wrapper('user_pass', $form_state);
  26. }
  27. elseif ($form_type == 'register') {
  28. // Show USER REGISTER form.
  29. $form_state['title'] = t('Create new account');
  30. $commands = ctools_modal_form_wrapper('user_register_form', $form_state);
  31. }
  32. elseif ($form_type == 'login') {
  33. // Show USER LOGIN form.
  34. $form_state['title'] = t('Login');
  35. $commands = ctools_modal_form_wrapper('user_login', $form_state);
  36. }
  37. // If form was submited.
  38. if (!empty($form_state['executed'])) {
  39. $commands = _ajax_register_execute_form($form_type, $form_state);
  40. }
  41. return array('#type' => 'ajax', '#commands' => $commands);
  42. }
  43. else {
  44. // If user has no js support redirect him to standart drupal forms.
  45. drupal_goto('user/' . $form_type);
  46. }
  47. }