0

I have previously added a confirmation dialog to my own forms using a technique like http://blog.purdy.info/2014/04/how-to-work-with-confirmform-in-drupal-7.html. However this assumes that you have control of the form builder and submit functions. I now want to add a confirmation to the user profile form which is of course defined in the user module.

Any suggestions ?

Thx

1 Answer 1

0

You can add your own submit handler in front the of the predefined submit handler using hook_form_alter().

The #submit property is an array of submit handlers and it allows multiple values. Use array_unshift() to put your handler in front of the predefined handler.

Your code will look something like this:

/**
 * Implements hook_form_alter().
 */
function mymodule_form_alter(&$form, &$form_state, $form_id){
  if ($form_id = 'target_form') { // make sure it's the right form
    // add my handler
    array_unshift($form['#submit'], 'my_submit');
  }
}

function my_submit( $form, &$form_state ) {
}

When the form is submitted, it will run my_submit() before the predefined submit handler.

1
  • The strategy for delivering the confirmation form requires modifying both the submit handler ( as you have suggested ) AND the function defining the form itself so that it returns a different form if a flag is set. So unfortunately your answer is not a complete solution.
    – elb
    Jul 22, 2015 at 6:27

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.