You are here

function ajax_register_form_alter in Ajax Login/Register 7.4

Same name and namespace in other branches
  1. 6.2 ajax_register.module \ajax_register_form_alter()
  2. 6 ajax_register.module \ajax_register_form_alter()
  3. 7.3 ajax_register.module \ajax_register_form_alter()

Implements hook_form_alter().

File

./ajax_register.module, line 167

Code

function ajax_register_form_alter(&$form, &$form_state, $form_id) {

  // Create array with enabled ajax links.
  $enabled_links = array(
    'login',
    'register',
    'password',
  );
  switch ($form_id) {
    case 'user_login_block':

      // Include css and js for modal dialog.
      _ajax_register_include_modal();

      // Add links processed with CTools modal.
      $form['links'] = array(
        '#theme' => 'item_list',
        '#items' => _ajax_register_ajax_links($enabled_links, $form_id),
        '#attributes' => array(
          'class' => array(
            'ajax-register-links',
          ),
        ),
      );

      // Add html wrapper to form and #ajax to form submit.
      _ajax_register_add_ajax($form, $form_id);

      // Do not add to the user login block anything more.
      break;
    case 'user_login':
    case 'user_pass':
    case 'user_register_form':

      // Do not process form with AJAX that should be processed with CTools modal.
      $modal_links_enabled = variable_get('ajax_register_form_enable_modal_links', TRUE);
      if (!empty($form_state['ajax'])) {

        // Include css and js for modal dialog.
        _ajax_register_include_modal();

        // Add links processed with CTools modal.
        if ($modal_links_enabled) {
          $form['links'] = array(
            '#theme' => 'item_list',
            '#items' => _ajax_register_ajax_links($enabled_links, $form_id),
            '#attributes' => array(
              'class' => array(
                'ajax-register-links',
                'inline',
              ),
            ),
            '#weight' => -200,
            '#prefix' => '<div class="ajax-register-links-wrapper">',
            '#suffix' => '</div>',
          );
        }

        // Unset captcha from modal form.
        $hide_captcha = variable_get('ajax_register_hide_captcha', FALSE);
        if ($hide_captcha) {
          unset($form['captcha']);
        }
      }
      else {

        // Add html wrapper to form and #ajax to form submit.
        _ajax_register_add_ajax($form, $form_id);
      }
  }
}