0

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'];
dsm("error");
if(strlen($new_pass) < 8){

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

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. – kiamlaluno Mar 21 '16 at 14:35
  • As side note, the string passed to t() needs to be in English. – kiamlaluno Mar 21 '16 at 14:36
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.

UPDATE

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, privacy policy and cookie policy

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