I have created the module and it show the error in login block. But only problem with this did not show the error in first time. If user again enter the wrong username and password then it show the error. Why do not understand. I check the session value it store in first time but did not show on the screen only after second time.

function usermoved_form_user_login_block_alter(&$form, &$form_state) {
   $form['warning'] = array(
  '#value' => t(''),
   '#weight' => 11

   $form['#validate'][] = 'usermoved_form_validate_code';

function usermoved_form_validate_code(&$form, &$form_state) {
   if (empty($form_state['uid'])) {
       form_set_error('warning', t('Sorry, unrecognized username or password.'));
     $_SESSION['usermoved_form_user_login_block_alter'] = t('The error message');
  else {
  • Have you looked at how form_set_error() works? Look at this topic. Or is there any reason why you can't use it? In that case, please tell us about it. – hampusn Sep 12 '12 at 6:24
  • If you set specify the form field in form_set_error(), it should print an error message above the field. You can probably use hook_form_alter() to move the error message around. – hampusn Sep 12 '12 at 7:03
  • The first parameter of form_set_error() takes your field's name. If you don't know what the name is, you can get it by print_r($form_state['values']); and look at the array keys. It's actually explained quite well on api.drupal.org/api/drupal/includes!form.inc/function/…. – hampusn Sep 12 '12 at 8:07
  • Please update your question with your new code. warning doesn't look like an actual field. I'm not sure if you can use form_set_error() on a form item of the type markup. What's the name of the username and the password field? – hampusn Sep 12 '12 at 9:17
  • i updated code the name of field is name and pass of login form – user1480032 Sep 12 '12 at 10:24

Your Answer

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

Browse other questions tagged or ask your own question.