TransWikia.com

How to create simple confirmation page?

Drupal Answers Asked by MathewDragon on November 11, 2020

I want to create simple confirmation page. It means that after user change his email then he gets confirmation email with link to page. This link contains token. This link should open page for user with appropriate message (success or fail if token expired). I want to create simple module, But I don’t know which hook I should use to create this simple page. I must check this token by sending POST request to REST API before rendering page.

Any advice?

3 Answers

I wrote a blog post that you may find helpful. Good luck!

Answered by Purdy on November 11, 2020

function custom_menu() {
  $items = array();
  $items['admin/sendmail/%'] = array(
    'title' => t('Delete Entry'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('custom_confirm_form'),
    'access arguments' => array('send mail'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

  function custom_confirm_form($form_state){
    return confirm_form($form, t('Are you sure you want to Send Mail?'), //message title
    'admin/send-mail', //redirect if cancelled
    t('Only say yes if you are really sure. Otherwise please click on cancel button.'), //message description
    t('Yes'), //confirm button text
    t('Cancel') //cancel button text
  );
}

function custom_confirm_form_submit($form, &$form_state){
   //verify that the form was confirmed
  if ($form_state['values']['confirm']) {  
     custom_send_mail();
  }
}

Answered by vishal sirsodiya on November 11, 2020

I suggest you use hook_user_update. Then you compare $account->mail and $account->original->mail. If the two email addresses are different, the user's email address changed. Next you generate the token and send an email to the user with a link to your page.

For the page, create a new menu entry via hook_menu and do the logic for the REST call there. You can get URL query parameters (especially the token) by using drupal_get_query_parameters. Maybe you should ensure that the token is unique and store it with the email address and the creation time (to check if it has expired) in the database.

The documentation for hook_menu (or 99% of all other modules available) should give you an example on how to use it.

Answered by schlicki on November 11, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP