PasswordConfirm::validatePasswordConfirm

public static PasswordConfirm::validatePasswordConfirm(&$element, FormStateInterface $form_state, &$complete_form)

Validates a password_confirm element.

File

core/lib/Drupal/Core/Render/Element/PasswordConfirm.php, line 97

Class

PasswordConfirm
Provides a form element for double-input of passwords.

Namespace

Drupal\Core\Render\Element

Code

public static function validatePasswordConfirm(&$element, FormStateInterface $form_state, &$complete_form) {
  $pass1 = trim($element['pass1']['#value']);
  $pass2 = trim($element['pass2']['#value']);
  if (strlen($pass1) > 0 || strlen($pass2) > 0) {
    if (strcmp($pass1, $pass2)) {
      $form_state->setError($element, t('The specified passwords do not match.'));
    }
  }
  elseif ($element['#required'] && $form_state->getUserInput()) {
    $form_state->setError($element, t('Password field is required.'));
  }

  // Password field must be converted from a two-element array into a single
  // string regardless of validation results.
  $form_state->setValueForElement($element['pass1'], NULL);
  $form_state->setValueForElement($element['pass2'], NULL);
  $form_state->setValueForElement($element, $pass1);

  return $element;
}
doc_Drupal
2016-10-29 09:33:14
Comments
Leave a Comment

Please login to continue.