You are here

function colorbox_form_alter in Colorbox 7

Same name and namespace in other branches
  1. 6 colorbox.module \colorbox_form_alter()

Implements hook_form_alter(). Reformat the login form.

File

./colorbox.module, line 353
A light-weight, customizable lightbox plugin for jQuery 1.3

Code

function colorbox_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'user_login':
      if (arg(0) == 'user' && arg(1) == 'login' && arg(2) == 'colorbox') {
        $form['name']['#size'] = 25;
        $form['name']['#id'] = 'cbox-edit-name';
        $form['pass']['#size'] = 25;
        $form['pass']['#id'] = 'cbox-edit-pass';

        // Add links as needed.
        if (variable_get('colorbox_login_links', 0)) {
          $items = array();

          // Add standard links.
          if (variable_get('colorbox_login_links', 0) == 1) {
            if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
              $items[] = l(t('Create new account'), 'user/register', array(
                'attributes' => array(
                  'title' => t('Create a new user account.'),
                ),
              ));
            }
            $items[] = l(t('Request new password'), 'user/password', array(
              'attributes' => array(
                'title' => t('Request new password via e-mail.'),
              ),
            ));
          }

          // Add links that opens in a Colorbox.
          if (variable_get('colorbox_login_links', 0) == 2) {
            if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
              $items[] = l(t('Create new account'), 'colorbox/form/user_register_form', array(
                'query' => array(
                  'width' => '300',
                  'height' => 'auto',
                ),
                'attributes' => array(
                  'title' => t('Create a new user account.'),
                  'class' => 'colorbox-load',
                ),
              ));
            }
            $items[] = l(t('Request new password'), 'colorbox/form/user_pass', array(
              'query' => array(
                'width' => '300',
                'height' => '150',
              ),
              'attributes' => array(
                'title' => t('Request new password via e-mail.'),
                'class' => 'colorbox-load',
              ),
            ));
          }
          $form['links'] = array(
            '#markup' => theme('item_list', array(
              'items' => $items,
            )),
          );
        }
      }
      break;
    case 'user_register_form':
      if (arg(0) == 'colorbox' && arg(1) == 'form') {
        $form['account']['name']['#size'] = 30;
        $form['account']['mail']['#size'] = 30;
      }
      break;
    case 'user_pass':
      if (arg(0) == 'colorbox' && arg(1) == 'form') {
        $form['name']['#size'] = 30;
      }
      break;
  }
}