How is it possible to create simple confirmation popup dialog boxes in Drupal 7?

I've searched a lot, but I found tons of non-working suggestions and code.

  • 5
    If you found solutions that do not work (for you, or not at all) please tell us which solutions you tried out, and why it didn't work for you. Jun 8, 2011 at 10:38
  • Also give us a little more description of what the confirmation is for.
    – mpdonadio
    Jun 8, 2011 at 16:43

3 Answers 3


I got it!!!

Here's a simple 100% functioning exmple:

$form['delete'] = array(
    '#type' => 'submit',
    '#value' => t('Delete'),
    '#attributes' => array('onclick' => 'if(!confirm("Really Delete?")){return false;}'),

I hope this helps.

Happy coding :)

  • you should accept this if it solved your problem (click the check mark below the vote count)
    – Chaulky
    Jun 9, 2011 at 0:24
  • @Chaulky I want to check it, but a popup box showed up telling me that i can accept it tomorrow but not today! Don't worry, i check it tomorrow :)
    – Peter
    Jun 9, 2011 at 8:24
  • 2
    You'd be better off setting a class in attributes and then picking up that class in a javascript Drupal.behaviors wrapper.
    – cam8001
    Jun 9, 2011 at 12:39

Drupal has a native confirm_form() function, but it is server side rather than Javascript based, which is what I assume you mean.


There is a sandbox module which enables this type of functionality to be built relatively easily: https://www.drupal.org/sandbox/cmcintosh/2644004

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.