You are here

function colorbox_form_alter in Colorbox 6

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

Implementation of hook_form_alter(). Reformat the login form.

File

./colorbox.module, line 357
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['pass']['#size'] = 25;

        // 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', 1)) {
              $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', 1)) {
              $items[] = l(t('Create new account'), 'colorbox/form/user_register', array(
                'query' => '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' => 'width=300&height=150',
              'attributes' => array(
                'title' => t('Request new password via e-mail.'),
                'class' => 'colorbox-load',
              ),
            ));
          }
          $form['links'] = array(
            '#value' => theme('item_list', $items),
          );
        }
      }
      break;
    case 'user_register':
      if (arg(0) == 'colorbox' && arg(1) == 'form') {
        $form['name']['#size'] = 30;
        $form['mail']['#size'] = 30;
      }
      break;
    case 'user_pass':
      if (arg(0) == 'colorbox' && arg(1) == 'form') {
        $form['name']['#size'] = 30;
      }
      break;
  }
}