Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. //Form Alter, check for form user_form
  2. function base_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  3.  
  4. if ($form_id == 'user_form') {
  5. $form['#validate'][] = '_user_form_validation';
  6. }
  7.  
  8. }
  9.  
  10. //Validation example
  11. function _user_form_validation(&$form, \Drupal\Core\Form\FormStateInterface $form_state){
  12.  
  13. if ($form_state->hasValue('pass')) {
  14. $pass = $form_state->getValue('pass');
  15.  
  16. if (strlen($pass) < 6 ) {
  17. $form_state->setErrorByName('pass', t('Password length must be at least 6 characters.'));
  18. }
  19.  
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement