1

I have used a custom validate function.

function user_information_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_login' || 'user_login_block') {
    array_unshift($form['#validate'],'user_information_user_login_form_validate');
  }
}

function user_information_user_login_form_validate(&$form, &$form_state) {
  // print_r($form_state);
  form_set_error('name', t('Password invalid'));
}

But I am unable to log in to the site any more.

1

you cant submit your form because you have set the error.

the form set error should be applied inside some condition

 function user_information_user_login_form_validate(&$form, &$form_state) {
    //print_r($form_state);
    //set some condition 
     if($form_state["some_field"] != "somevalue")// only when the condition satisfies the form set error should display. if not all the time your from set error will be called 
      form_set_error('name', t('Password invalid'));
    }

above condition is a sample condition you have to replace it with your own condition for validating your password.

2
  • Ok I have to check if the username and password is not correct then display this sententce. In essence I will have to overwrite this message "Sorry, unrecognized username or password. Have you forgotten your password? " – user3418540 Feb 10 '15 at 8:46
  • refer this for overwrite the form set error message drupal.stackexchange.com/questions/39851/… – DEVARAJ JOHNSON Feb 10 '15 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.