You are here

function om_user_alter_form in OM Tools 6.2

OM Tools User Form Alters

File

tools/user/user.inc, line 74
User Tools

Code

function om_user_alter_form(&$form, &$form_state, $form_id) {
  global $user;
  if ($user->uid != 0) {
    $form_id = '';
  }
  $user_defaults = $form['om_user_tools_values']['#value'];

  // Make sure the js are added only once
  static $user_login_block_js = 0;
  static $user_login_js = 0;
  static $user_register_js = 0;
  static $user_pass_js = 0;
  switch ($form_id) {
    case "user_login_block":
      if ($user_defaults['user_login_block_switch']) {
        $user_login_block_label = $user_defaults['user_login_block_label'];
        $user_login_block_name_label_text = $user_defaults['user_login_block_name_label_text'];
        $user_login_block_pass_label_text = $user_defaults['user_login_block_pass_label_text'];
        $user_login_block_size = $user_defaults['user_login_block_size'];
        $user_login_block_name_hover = $user_defaults['user_login_block_name_hover'];
        $user_login_block_pass_hover = $user_defaults['user_login_block_pass_hover'];
        $user_login_block_button = $user_defaults['user_login_block_button'];
        $user_login_block_register = $user_defaults['user_login_block_register'];
        $user_login_block_password = $user_defaults['user_login_block_password'];
        $user_login_block_links = '<div class="item-list"><ul><li class="first"><a href="' . base_path() . 'user/register" title="Create a new user account.">' . $user_login_block_register . '</a></li> <li class="last"><a href="' . base_path() . 'user/password" title="Request new password via e-mail.">' . $user_login_block_password . '</a></li> </ul></div>';
        if ($user_login_block_label) {
          unset($form['name']['#title']);
          unset($form['pass']['#title']);

          //$form['name']['#default_value'] = $user_login_block_name_label_text;
          $user_login_block_js++;
          if ($user_login_block_js == 1) {
            drupal_add_js("\n            \$(document).ready(function(){\n              var userName = \$('#user-login-form input#edit-name').val();\n              var userLoginBlockNameLabelText = '" . $user_login_block_name_label_text . "';\n              \n              if(userName == '') {\n                \$('#user-login-form input#edit-name').val(userLoginBlockNameLabelText);\n              }\n              \$('#user-login-form input#edit-name').click(function() {\n                if(\$(this).val() == userLoginBlockNameLabelText) { \$(this).val(''); };\n              });\n              \$('#user-login-form input#edit-name').blur(function() {\n                if((\$(this).val() == userLoginBlockNameLabelText) || (\$(this).val() == '')) { \n                  \$(this).val(userLoginBlockNameLabelText); \n                }\n              });\n\n              \$('#user-login-form input#edit-pass').before(\"<input type='text' class='form-text' size='" . $user_login_block_size . "' maxlength='60' id='dummy-pass' name='dummy-pass' value='" . $user_login_block_pass_label_text . "' title='" . t($user_login_block_pass_hover) . "'>\");\n\n              \$('#user-login-form input#edit-pass').hide();\n              \$('#user-login-form input#dummy-pass').show();\n\n              \$('#user-login-form input#dummy-pass').focus(function() {\n                \$('#user-login-form input#dummy-pass').hide();\n                \$('#user-login-form input#edit-pass').show();\n                \$('#user-login-form input#edit-pass').focus();\n              });\n              \$('#user-login-form input#edit-pass').blur(function() {\n                if(\$('#user-login-form input#edit-pass').val() == '') {\n                  \$('#user-login-form input#dummy-pass').show();\n                  \$('#user-login-form input#edit-pass').hide();\n                } \n              });\n            });\n            ", "inline");
          }
        }
        else {
          $form['name']['#title'] = $user_login_block_name_label_text;
          $form['pass']['#title'] = $user_login_block_pass_label_text;
        }
        $form['name']['#size'] = $user_login_block_size;
        $form['name']['#attributes'] = array(
          'title' => t($user_login_block_name_hover),
        );
        $form['pass']['#size'] = $user_login_block_size;
        $form['pass']['#attributes'] = array(
          'title' => t($user_login_block_pass_hover),
        );
        $form['submit'] = array(
          '#type' => 'submit',
          '#value' => t($user_login_block_button),
        );
        $form['links']['#value'] = $user_login_block_links;
      }
      break;
    case "user_login":
      if ($user_defaults['user_login_switch']) {
        drupal_set_title(t($user_defaults['user_login_title']));
        $user_login_label = $user_defaults['user_login_label'];
        $user_login_name_label_text = $user_defaults['user_login_name_label_text'];
        $user_login_name_description = $user_defaults['user_login_name_description'];
        $user_login_pass_label_text = $user_defaults['user_login_pass_label_text'];
        $user_login_pass_description = $user_defaults['user_login_pass_description'];
        $user_login_size = $user_defaults['user_login_size'];
        $user_login_name_hover = $user_defaults['user_login_name_hover'];
        $user_login_pass_hover = $user_defaults['user_login_pass_hover'];
        $user_login_button = $user_defaults['user_login_button'];
        if ($user_login_label) {
          unset($form['name']['#title']);
          unset($form['pass']['#title']);

          //$form['name']['#default_value'] = $user_login_name_label_text;
          $user_login_js++;
          if ($user_login_js == 1) {
            drupal_add_js("\n\n            \$(document).ready(function(){\n              var userName = \$('#user-login input#edit-name').val();\n              var userLoginNameLabelText = '" . $user_login_name_label_text . "';\n              if(userName == '') {\n                \$('#user-login input#edit-name').val(userLoginNameLabelText);\n              }\n              \$('#user-login input#edit-name').click(function() {\n                if(\$(this).val() == userLoginNameLabelText) { \$(this).val(''); };\n              });\n              \$('#user-login input#edit-name').blur(function() {\n                if((\$(this).val() == userLoginNameLabelText) || (\$(this).val() == '')) { \n                  \$(this).val(userLoginNameLabelText); \n                }\n              });\n\n              \$('#user-login input#edit-pass').before(\"<input type='text' class='form-text' size='" . $user_login_size . "' maxlength='60' id='dummy-pass' name='dummy-pass' value='" . $user_login_pass_label_text . "' title='" . t($user_login_pass_hover) . "'>\");\n\n              \$('#user-login input#edit-pass').hide();\n              \$('#user-login input#dummy-pass').show();\n\n              \$('#user-login input#dummy-pass').focus(function() {\n                \$('#user-login input#dummy-pass').hide();\n                \$('#user-login input#edit-pass').show();\n                \$('#user-login input#edit-pass').focus();\n              });\n              \$('#user-login input#edit-pass').blur(function() {\n                if(\$('#user-login input#edit-pass').val() == '') {\n                  \$('#user-login input#dummy-pass').show();\n                  \$('#user-login input#edit-pass').hide();\n                } \n              });\n            });\n            ", "inline");
          }
        }
        else {
          $form['name']['#title'] = $user_login_name_label_text;
          $form['pass']['#title'] = $user_login_pass_label_text;
        }
        $form['name']['#description'] = $user_login_name_description;
        $form['name']['#size'] = $user_login_size;
        $form['name']['#attributes'] = array(
          'title' => t($user_login_name_hover),
        );
        $form['pass']['#description'] = $user_login_pass_description;
        $form['pass']['#size'] = $user_login_size;
        $form['pass']['#attributes'] = array(
          'title' => t($user_login_pass_hover),
        );
        $form['submit'] = array(
          '#type' => 'submit',
          '#value' => t($user_login_button),
        );
      }
      break;
    case "user_register":
      if ($user_defaults['user_register_switch']) {
        drupal_set_title(t($user_defaults['user_register_title']));
        $user_register_label = $user_defaults['user_register_label'];
        $user_register_name_label_text = $user_defaults['user_register_name_label_text'];
        $user_register_name_description = $user_defaults['user_register_name_description'];
        $user_register_mail_label_text = $user_defaults['user_register_mail_label_text'];
        $user_register_mail_description = $user_defaults['user_register_mail_description'];
        $user_register_size = $user_defaults['user_register_size'];
        $user_register_name_hover = $user_defaults['user_register_name_hover'];
        $user_register_mail_hover = $user_defaults['user_register_mail_hover'];
        $user_register_button = $user_defaults['user_register_button'];
        if ($user_register_label) {
          unset($form['name']['#title']);
          unset($form['mail']['#title']);

          //$form['name']['#default_value'] = $user_register_name_label_text;
          $user_register_js++;
          if ($user_register_js == 1) {
            drupal_add_js("\n\n          \$(document).ready(function(){\n            var userName = \$('#user-register input#edit-name').val();\n            var userRegisterNameLabelText = '" . $user_register_name_label_text . "';\n            var userRegisterMailLabelText = '" . $user_register_mail_label_text . "';\n            if(userName == '') {\n              \$('#user-register input#edit-name').val(userRegisterNameLabelText);\n            }\n            \$('#user-register input#edit-name').click(function() {\n              if(\$(this).val() == userRegisterNameLabelText) { \$(this).val(''); };\n            });\n            \$('#user-register input#edit-name').blur(function() {\n              if((\$(this).val() == userRegisterNameLabelText) || (\$(this).val() == '')) { \n                 \$(this).val(userRegisterNameLabelText); \n              }\n            });\n            if(userName == '') {\n              \$('#user-register input#edit-name-1').val(userRegisterNameLabelText);\n            }\n            \$('#user-register input#edit-name-1').click(function() {\n              if(\$(this).val() == userRegisterNameLabelText) { \$(this).val(''); };\n            });\n            \$('#user-register input#edit-name-1').blur(function() {\n              if((\$(this).val() == userRegisterNameLabelText) || (\$(this).val() == '')) { \n                 \$(this).val(userRegisterNameLabelText); \n              }\n            });\n\n            \$('#user-register input#edit-mail').val(userRegisterMailLabelText);\n              \$('#user-register input#edit-mail').click(function() {\n              if(\$(this).val() == userRegisterMailLabelText) { \$(this).val(''); };\n            });\n            \$('#user-register input#edit-mail').blur(function() {\n              if((\$(this).val() == userRegisterMailLabelText) || (\$(this).val() == '')) { \n                 \$(this).val(userRegisterMailLabelText); \n              }\n            });\n          });\n          ", "inline");
          }
        }
        else {
          $form['name']['#title'] = $user_register_name_label_text;
          $form['mail']['#title'] = $user_register_mail_label_text;
        }
        $form['name']['#description'] = $user_register_name_description;
        $form['name']['#size'] = $user_register_size;
        $form['name']['#attributes'] = array(
          'title' => t($user_register_name_hover),
        );
        $form['mail']['#description'] = $user_register_mail_description;
        $form['mail']['#size'] = $user_register_size;
        $form['mail']['#attributes'] = array(
          'title' => t($user_register_mail_hover),
        );
        $form['submit'] = array(
          '#type' => 'submit',
          '#value' => t($user_register_button),
        );
      }
      break;
    case "user_pass":
      if ($user_defaults['user_pass_switch']) {
        drupal_set_title(t($user_defaults['user_pass_title']));
        $user_pass_label = $user_defaults['user_pass_label'];
        $user_pass_name_label_text = $user_defaults['user_pass_name_label_text'];
        $user_pass_name_description = $user_defaults['user_pass_name_description'];
        $user_pass_size = $user_defaults['user_pass_size'];
        $user_pass_name_hover = $user_defaults['user_pass_name_hover'];
        $user_pass_button = $user_defaults['user_pass_button'];
        if ($user_pass_label) {
          unset($form['name']['#title']);
          unset($form['mail']['#title']);

          //$form['name']['#default_value'] = $user_pass_name_label_text;
          $user_pass_js++;
          if ($user_pass_js == 1) {
            drupal_add_js("\n          \$(document).ready(function(){\n            var userPassNameLabelText = '" . $user_pass_name_label_text . "';\n            \$('#user-pass input#edit-name').val(userPassNameLabelText);\n            \$('#user-pass input#edit-name').click(function() {\n              if(\$(this).val() == userPassNameLabelText) { \$(this).val(''); };\n            });\n            \$('#user-pass input#edit-name').blur(function() {\n              if((\$(this).val() == userPassNameLabelText) || (\$(this).val() == '')) { \n                 \$(this).val(userPassNameLabelText); \n              }\n            });\n          });\n        ", "inline");
          }
        }
        else {
          $form['name']['#title'] = $user_pass_name_label_text;
        }
        $form['name']['#description'] = $user_pass_name_description;
        $form['name']['#size'] = $user_pass_size;
        $form['name']['#attributes'] = array(
          'title' => t($user_pass_name_hover),
        );
        $form['submit'] = array(
          '#type' => 'submit',
          '#value' => t($user_pass_button),
        );
      }
      break;
  }
}