I'm using Drupal 7, i want to display a message drupal_set_message, when i click on a button for example.

When i'm logged it works well, but for this same button (or page) if i'm not logged in, it doesn't display any message.

This is my case : i've created a mobile application that used a backoffice. this backoffice is built using drupal. i've created a page "reset password" user can click on "reset password" from the mobile app, an email sent with a link to my custom page : reset_pwd

this page contains inputs to reset new password :

$items['reset_psw'] = array(
'title' => '',
    'description' => '',
    'access arguments' => array('administer reset_psw'),
    'file' => 'system.admin.inc',
    'file path' => drupal_get_path('module', 'system'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('reset_mdp_formulaire'),
return $items;

the form to reset password :

function reset_mdp_formulaire ($form, &$form_state){

$form = array();

$form['confirm_pass'] = array(
    '#type' => 'password_confirm',       

$form['valider'] = array(
    '#value' => t('valider'),
    '#type' => 'submit',           
return $form;

the function submit :

function reset_mdp_formulaire_submit ($form, &$form_state){
$new_pass = $form_state['values']['confirm_pass'];
if(strlen($new_pass) < 8){

    drupal_set_message(t('Password must be 8 characters at least.'), 'error'); <== not shown when logged out

Just want to check if new password is less than 8 characters, and display error message

Thank you all.

  • 1
    It's the validation handler that should show such errors. drupal_set_message() works for anonymous users too, so the error is somewhere else.
    – apaderno
    Commented Mar 21, 2016 at 14:35
  • As side note, the string passed to t() needs to be in English.
    – apaderno
    Commented Mar 21, 2016 at 14:36

1 Answer 1


Try removing the return statement at the end of your submit or even replacing it with a drupal_goto('reset_psw').

There are lots of similar questions on google and S.O., you could have a look.


You should use the validate handler for such a case, this simple example should get you going https://www.drupal.org/node/717740

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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