You are here

function securelogin_form_alter in Secure Login 5

Same name and namespace in other branches
  1. 8 securelogin.module \securelogin_form_alter()
  2. 6 securelogin.module \securelogin_form_alter()
  3. 7 securelogin.module \securelogin_form_alter()

Alter address in password forms

File

./securelogin.module, line 97

Code

function securelogin_form_alter($form_id, &$form) {
  global $base_url;
  if ($form_id == 'user_login_block' && variable_get('securelogin_loginform', TRUE) == TRUE || $form_id == 'user_login' && variable_get('securelogin_loginform', TRUE) == TRUE || $form_id == 'user_edit' && variable_get('securelogin_editform', TRUE) == TRUE || $form_id == 'user_register' && variable_get('securelogin_registerform', TRUE) == TRUE) {

    // Get original base URL
    $origurl = isset($_REQUEST['securelogin_original_baseurl']) ? $_REQUEST['securelogin_original_baseurl'] : $base_url;

    // Get secure URL
    $securl = variable_get('securelogin_baseurl', preg_replace('@^http://@', 'https://', $base_url));

    // Strip trailing slash from base_path
    $base = rtrim(base_path(), '/');

    // Redirect form to secure page, if necessary
    if (variable_get('securelogin_secure_forms', FALSE) == TRUE) {
      $secformurl = $securl . '/' . $_GET['q'];
      if ($_SERVER['SCRIPT_URI'] != $secformurl) {
        drupal_goto($secformurl, 'securelogin_original_baseurl=' . urlencode($origurl));
      }
    }

    // Set form action
    $form['#action'] = preg_replace('@^' . $base . '@', $securl, $form['#action']);

    // Add field to remember original base URL
    $form['securelogin_original_baseurl'] = array(
      '#type' => 'hidden',
      '#value' => $origurl,
    );
  }
}