ajax_register.admin.inc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * @file
  4. * Provides form with AJAX REGISTER module settings.
  5. */
  6. /**
  7. * Administrative settings form.
  8. */
  9. function ajax_register_admin_form($form, $form_state) {
  10. $form['ajax_register_modal'] = array(
  11. '#type' => 'fieldset',
  12. '#title' => t('Modal window settings'),
  13. );
  14. $form['ajax_register_modal']['ajax_register_modal_width'] = array(
  15. '#type' => 'textfield',
  16. '#title' => t('Modal window width'),
  17. '#size' => 4,
  18. '#field_suffix' => 'px',
  19. '#default_value' => variable_get('ajax_register_modal_width', 550),
  20. );
  21. $form['ajax_register_modal']['ajax_register_modal_background_opacity'] = array(
  22. '#type' => 'select',
  23. '#title' => t('Background opacity'),
  24. '#options' => array(
  25. '0' => '0%',
  26. '0.1' => '10%',
  27. '0.2' => '20%',
  28. '0.3' => '30%',
  29. '0.4' => '40%',
  30. '0.5' => '50%',
  31. '0.6' => '60%',
  32. '0.7' => '70%',
  33. '0.8' => '80%',
  34. '0.9' => '90%',
  35. '1' => '100%',
  36. ),
  37. '#default_value' => variable_get('ajax_register_modal_background_opacity', '0.7'),
  38. );
  39. $form['ajax_register_modal']['ajax_register_modal_background_color'] = array(
  40. '#type' => 'textfield',
  41. '#title' => t('Background color'),
  42. '#size' => 6,
  43. '#maxlength' => 6,
  44. '#field_prefix' => '#',
  45. '#default_value' => variable_get('ajax_register_modal_background_color', '000000'),
  46. );
  47. $form['ajax_register_modal']['ajax_register_hide_captcha'] = array(
  48. '#type' => 'checkbox',
  49. '#title' => t('Hide captcha in modal dialog'),
  50. '#description' => t('Capctha protects your site from spambots.
  51. But they have no js enabled, so spambots will never see modal dialog and will be redirected to normal login/register form with captcha.'),
  52. '#default_value' => variable_get('ajax_register_hide_captcha', FALSE),
  53. );
  54. if (!module_exists('captcha')) {
  55. $form['ajax_register_modal']['ajax_register_hide_captcha']['#disabled'] = TRUE;
  56. $form['ajax_register_modal']['ajax_register_hide_captcha']['#title'] .= ' (' . t('requires CAPTCHA module') . ')';
  57. }
  58. $form['ajax_register_forms'] = array(
  59. '#type' => 'fieldset',
  60. '#title' => t('Form settings'),
  61. );
  62. $form['ajax_register_forms']['ajax_register_form_enable_modal_links'] = array(
  63. '#type' => 'checkbox',
  64. '#title' => t('Enable links in modal window'),
  65. '#description' => t('Check if links to another forms should appear in modal form'),
  66. '#default_value' => variable_get('ajax_register_form_enable_modal_links', TRUE),
  67. );
  68. // Login form settings.
  69. $form['ajax_register_forms']['login'] = array(
  70. '#type' => 'fieldset',
  71. '#title' => t('Login'),
  72. );
  73. // Add redirect settings to the login form type.
  74. ajax_register_add_redirect_settings($form['ajax_register_forms']['login'], $form_state, 'login');
  75. // Register form settings.
  76. $form['ajax_register_forms']['register'] = array(
  77. '#type' => 'fieldset',
  78. '#title' => t('Register'),
  79. );
  80. // Add redirect settings to the register form type.
  81. ajax_register_add_redirect_settings($form['ajax_register_forms']['register'], $form_state, 'register');
  82. // Password form settings.
  83. $form['ajax_register_forms']['password'] = array(
  84. '#type' => 'fieldset',
  85. '#title' => t('Password'),
  86. );
  87. // Add redirect settings to the password form type.
  88. ajax_register_add_redirect_settings($form['ajax_register_forms']['password'], $form_state, 'password');
  89. // Return the form.
  90. return system_settings_form($form);
  91. }
  92. /**
  93. * Adds standard redirect options to admin form for different form types.
  94. */
  95. function ajax_register_add_redirect_settings(&$form, &$form_state, $form_type) {
  96. // Provide a list of redirect behaviors.
  97. $redirect_behaviors = array(
  98. 'default' => t('Default'),
  99. 'refresh' => t('Refresh'),
  100. 'custom' => t('Custom'),
  101. );
  102. // Only provide the no redirect behavior for non-login forms.
  103. if ($form_type != 'login') {
  104. $redirect_behaviors['none'] = t('No Redirect');
  105. }
  106. // Provide descriptions for redirect behaviors.
  107. $redirect_descriptions = array(
  108. t('Default') => t('After successful submission of the form, the redirect path is handled by Drupal and will redirect the user to whatever the !form_state_redirect variable is set to. NOTE: This option may be required if there are additional modules or features that handle the redirect logic.', array(
  109. '!form_state_redirect' => $form_state['redirect'],
  110. )),
  111. t('Refresh') => t('After successful submission of the form, the page will be refreshed.'),
  112. t('Custom') => t('After successful submission of the form, users will be redirected to this manually set custom URL.'),
  113. );
  114. // Only provide the no redirect behavior for non-login forms.
  115. if ($form_type != 'login') {
  116. $redirect_descriptions[t('No Redirect')] = t('After successful submission of the form, the modal window will simply close and not redirect the user to any location.');
  117. }
  118. // Theme descriptions as an item list.
  119. $items = array();
  120. foreach ($redirect_descriptions as $title => $description) {
  121. $items[] = '<strong>' . $title . '</strong> - ' . $description;
  122. }
  123. $redirect_description = theme('item_list', array('items' => $items));
  124. // Provide a wrapper for ajax callback.
  125. $form['redirect'] = array(
  126. '#prefix' => '<div id="ajax-register-forms-' . $form_type . '-redirect">',
  127. '#suffix' => '</div>',
  128. );
  129. // Determine the default value for the dropdown.
  130. $selected = variable_get('ajax_register_' . $form_type . '_redirect_behavior', 'default');
  131. if (isset($form_state['values']['ajax_register_' . $form_type . '_redirect_behavior'])) {
  132. $selected = $form_state['values']['ajax_register_' . $form_type . '_redirect_behavior'];
  133. }
  134. $form['redirect']['ajax_register_' . $form_type . '_redirect_behavior'] = array(
  135. '#form_type' => $form_type,
  136. '#type' => 'select',
  137. '#title' => 'Redirect Behavior',
  138. '#description' => $redirect_description,
  139. '#options' => $redirect_behaviors,
  140. '#default_value' => $selected,
  141. '#ajax' => array(
  142. 'callback' => 'ajax_register_admin_form_redirect_callback',
  143. 'wrapper' => 'ajax-register-forms-' . $form_type . '-redirect',
  144. ),
  145. );
  146. // Only show the redirect URL if the behavior type is custom.
  147. if ($selected == 'custom') {
  148. $form['redirect']['ajax_register_' . $form_type . '_redirect_url'] = array(
  149. '#type' => 'textfield',
  150. '#title' => t('Redirect URL'),
  151. '#description' => t('Enter the URL that the user will be redirected to after a successful login.'),
  152. '#default_value' => variable_get('ajax_register_' . $form_type . '_redirect_url', ''),
  153. // Make this field required, since this is a custom redirect behavior.
  154. '#required' => TRUE,
  155. );
  156. }
  157. }
  158. /**
  159. * Ajax callback to re-render the selected form type's redirect options.
  160. */
  161. function ajax_register_admin_form_redirect_callback($form, $form_state) {
  162. $form_type = isset($form_state['triggering_element']['#form_type']) ? $form_state['triggering_element']['#form_type'] : FALSE;
  163. if ($form_type) {
  164. return $form['ajax_register_forms'][$form_type]['redirect'];
  165. }
  166. }