Basically, there is a module I'm using and there is a submit button on the page.

When the user clicks submit, it validates and processes the user input before going to the next page.

What I want to happen is that when a user clicks submit, the form does the default behavior of validating and processing the user input. But then I want to add a popup depending on if the previous input is valid. There will also be a button on the popup to take you to the next page.

How can I do this, if at all?

1 Answer 1


In a custom module, implement hook_form_FORM_ID_alter(). In there, the $form['#submit'] element is an array of all the functions that will handle a valid form submission. You can add your function to that array to have it executed on (valid) submission. Submit handler functions are executed in the order of the array, so the best is probably to append yours at the end. If the array is empty, you need to create the array and it must contains default submit handler in addition to yours, otherwise your will loose the default behavior.

To open a popup, you will need some custom JavaScript to the page trough drupal_add_js() (which you would call from your submit handler). In your custom JavaScript, you can use jQuery UI Dialog library bundled with Drupal 7. To have the library available on the page use drupal_add_library('system', 'ui.dialog'). You can use drupal_add_js() to pass data from your validation handler to your JavaScript code using the setting type.

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.