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']) {  

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!

Related Questions

Changing library path with hook_library_info_alter

1  Asked on September 8, 2020 by extect


How can execute batch api over cron jobs

3  Asked on September 6, 2020 by johntang


How can I programatically add a shipping method to a store?

1  Asked on September 4, 2020 by vintorg


Local Dev .theme file not loading

1  Asked on September 4, 2020 by jmichael


Webform submitted data in views

5  Asked on August 31, 2020 by user3783391


Export and Import Taxonomies and Extra Fields

1  Asked on August 21, 2020 by monkeyuser


How to resolve lazy_builder error?

1  Asked on August 19, 2020 by usernameabc


redirect whole site to HTTPS

3  Asked on August 11, 2020 by naomisl


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir