Hi

Some of our site users seem to have trouble reading the green message ["Further instructions have been sent to your e-mail address."] that appears when they use the request new password form.
Rather than actually checking their email as instructed, they are writing to tech support and moaning that the request password process is broken [it's not, its an EBKAC in these cases].

Tech support are now getting frustrated at some users lack of ability to read big green messages and would like me to change the request new password process.

Instead of the request new password ending up on the login [/user] page, can I either remain on the request new password page [/user/password] with an appropriate message, or can I end up redirecting to a custom page? The custom page would be preferable as there would be no form on it to confuse them.

I have tried a quick custom module to see if this would actually work:

function theme_form_alter(&$form, &$form_state) {
  if ($form['#action'] == "/user/password"){
     $form['#action'] = "/custom-page";
  }
}

and it does exactly as it should, set the form action to the /custom-page, but the form processing on the original /user/password is no longer there so nothing actually happens. ;) So no real surprises there.

Any suggestions would be gratefully received,

thank you for your help
ice70

Comments

gbrands’s picture

Try using the 'redirect' key instead of #action and the $form_state:

$form_state['redirect'] = 'custom-page';

See drupal_redirect_form() for more info

ice70’s picture

Hi,

thank you for your reply.

I have updated the function as follows:

function m2f_password_reset_form_alter(&$form, &$form_state) {
  if ($form['#action'] == "/user/password"){
  print("<pre>");
  var_dump($form_state);
  print("</pre>");
  $form_state['redirect'] = "node/20";
  print("<pre>");
  var_dump($form_state);
  print("</pre>");
  }
}

The second var_dump($form_state) output is

array(13) {
  ["build_info"]=>
    array(2) {
      ["args"]=> array(0) { }
      ["files"]=> array(1) {
          ["menu"]=> string(27) "modules/user/user.pages.inc"
        }
    }
  ["rebuild"]=> bool(false)
  ["rebuild_info"]=> array(0) {  }
  ["redirect"]=> string(7) "node/20"
  ["temporary"]=>  array(0) {}
  ["submitted"]=> bool(false)
  ["executed"]=>  bool(false)
  ["programmed"]=>  bool(false)
  ["cache"]=> bool(false)
  ["method"]=>  string(4) "post"
  ["groups"]=>  array(0) { }
  ["buttons"]=>  array(0) { }
  ["input"]=> array(0) { }
}

The only difference between the first and second var_dump() is
first output
["redirect"]=> NULL
second output
["redirect"]=> string(7) "node/20"

I have tried using various permutations of:
$form_state['redirect'] = "node/20";

$form_state['redirect'] = "/node/20";
$form_state['redirect'] = "http://www.domain.com/node/20";
$form_state['redirect'] = "url_alias name";
$form_state['redirect'] = "/url_alias name";
$form_state['redirect'] = "http://www.domain.com/url_alias name";

and so on, but each time I do a new password request, the form processes and end up at
/user

with the green message saying the email has been sent.

I have checked the triggers that prevent redirection on the link sent through drupal_redirect_form()

If $form_state['redirect'] is FALSE, a form builder function or form validation/submit handler does not want a user to be redirected, which means that drupal_goto() is not invoked.
If $form_state['no_redirect'] is TRUE, then the callback that originally built the form explicitly disallows any redirection, regardless of the redirection value in $form_state['redirect'].
If $form_state['programmed'] is TRUE, the form submission was usually invoked via drupal_form_submit(), so any redirection would break the script that invoked drupal_form_submit().
If $form_state['rebuild'] is TRUE, the form needs to be rebuilt without redirection.

And the var_dump() does not look to meet any of these.

Any idea what I have missed?

Thank you for your help
ice70

gbrands’s picture

Perhaps try altering the $form_state['redirect'] in a submit handler. Something like this:

/**
 * Implements hook_form_alter().
 */
function m2f_password_reset_form_alter(&$form, &$form_state) {
  if ($form['#action'] == "/user/password"){
    $form['#submit'][] = 'm2f_password_redirect';
  }
}
/**
 * Redirects user after password reset form is filled
 */
function m2f_password_redirect(&$form, &$form_state){
  $form_state['redirect'] = 'node/20';
}

Hope this helps!

ice70’s picture

Hi Gerrit Brands

that works exactly as it should, thank you for your help! :)

ice70

shadowdknight’s picture

Hi,
I have the same struggle, can anyone post this as module for D7?

Thanks

dianacastillo’s picture

I put this into my template.php and it works for me

function mytheme_form_alter(&$form, &$form_state, $form_id) { 
 if ($form_id =='user_pass'){
      $form['#submit'][] = 'mytheme_password_redirect';
  }
}
/**
* Redirects user after password reset form is filled
*/
function mytheme_password_redirect(&$form, &$form_state){
  $form_state['redirect'] = 'node/889';
}

Diana Castillo

Vali Hutchison’s picture

Worked for me too - I created a page with more info about checking spam folder etc and redirected to that.

Like the OP, we regularly get users complaining that they do a password reset and then are asked to enter their password, but they don't know it - they just haven't read the status message about the email being sent to them and simply think they are now being asked to login.

I've also combined this with this module https://www.drupal.org/project/simple_pass_reset to then provide a simple form after clicking the password reset link that just shows the password fields where they can enter their new ones - rather than the whole user profile, which again led to confusion as users then don't realise they need to enter a new password after clicking the link.

boabjohn’s picture

Hi guys, sorry very much a noob at the template level. I tried to paste in @dianacastillo's function in template.php, cleared caches, etc...but still not getting a re-direct to my specified node.

Strange that this "trigger" does not appear in the list of core actions that Drupal knows about. If it were acknowledged as a proper action then I could solve the problem very simply with Rules.

Any help with the function would be greatly appreciated.

John Brisbin
Managing Director, BoaB interactive

[mb] +61 (0)4 0747 1565
[im] skype:boabjohn
[www] http://www.boab.info
[ph] +61 (0)7 4094 2172
[m] POB 248 MT Molloy QLD 4871 AUSTRALIA

umeshpatil’s picture

Hello Boabjohn,

I have created a custom trigger for this, I will try to patch this into Drupal 7 if the drupal.org approves.

Please find my comment below for the code.

Thanks!!

tapash’s picture

Hi, @vali hutchinson I have added the following code to simple_pass_reset.module, at the bottom of the page

function simple_pass_reset_form_alter(&$form, &$form_state, $form_id) { 
 if ($form_id =='user_pass'){
      $form['#submit'][] = 'simple_pass_reset_password_redirect';
  }
}
/**
* Redirects user after password reset form is filled
*/
function simple_pass_reset_password_redirect(&$form, &$form_state){
  $form_state['redirect'] = '<front>';
}

but the page does not redirect to front page after submitting a new password. Do I need to modify anything in the l module file? thanks

Katy Jockelson’s picture

Thanks for the simple snippet - works for me, and saves the confusion of the end user still seeing a login form when that's the page they've just come from. 

umeshpatil’s picture

Hello Guys,

To achieve this, I prefer to have a custom trigger which will give freedom to end user to select the page of his choice whenever he/she wants, instead of fiddling with code every time. Use below code to create a custom module and install it in your environment. Once done you will find the trigger in your triggers list.

/**
 * Implements hook_trigger_info().
 * 
 * Below we have created one trigger for passoword reset which will help user to define an action for it based on the req.
 * 
 * The trigger belongs to User group and has a custom created hook called user_password_reset
 * 
 * This will appear in the list of triggers
 */

function your_module_trigger_info() {
	return array(
			'user' => array(
					'user_password_reset' => array(
							'label' => t('After password reset'),
					),
			),
	);
}

/**
 * 
 * @param  $form Form data
 * @param  $form_state 
 * @param  $form_id
 * 
 * Implemtents hook_form_FORM_ID_alter(&$form, &$form_state, $form_id)
 * 
 * This is used to call our trigger event on password reset request form submit
 */

function your_module_form_user_pass_alter( &$form, &$form_state, $form_id) {
	$form['#submit'][] = 'your_module_user_password_reset';
}

/**
 *  Custom function your_module_user_password_reset()
 *  
 *  This will execute actions assigned to the trigger.
 */

function your_module_user_password_reset() {
	$aids = trigger_get_assigned_actions('user_password_reset');
	
	$context = array(
			'group' => 'user',
			'hook' => 'user_password_reset',
	);
	
	actions_do(array_keys($aids), (object) $options, $context);
}

Please let me know if you find any issues with it.

Thanks!!

HunterElliott’s picture

@umeshpatil This does work - the user is redirected to a specific page after the password reset link is clicked...
however I'm getting the following error:
Notice: Undefined variable: options in [modulename]_user_password_reset() (line 61 of /var/www/html/[site]/sites/all/modules/_custom/[modulename]/[modulename].module).

Line 61 reads:

  actions_do(array_keys($aids), (object) $options, $context);

Suggestions on how to get rid of the error would be appreciated.

HunterElliott’s picture

I went and added a line to the last part of your code and, at least for me, it resolved the error messages. I just added "$options = array();" to the last function. It now reads as follows (without my "added line" comment):

function yourmodulename_user_password_reset() {
  $aids = trigger_get_assigned_actions('user_password_reset');
  $options = array(); /* added line */

  $context = array(
    'group' => 'user',
    'hook' => 'user_password_reset',
  );

  actions_do(array_keys($aids), (object) $options, $context);
}