Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By dima.zub on
I'm developing own module.
Have a form - but after submit I want to open popup and show result of submiting form in this window no at the same page with form.
How to do this?
Thank you.
Comments
Ctools AJax Modals
You will probably want to look at CTools. It has ways for creating AJAX forms, including modals. Pop-ups are the most common type of modals.
--
Read more at iRolo.net
You can do this by setting
You can do this by setting your form to submit through AJAX, then calling the popup in your AJAX response. Let's imagine the module is called form_popup
1) Create your form definition:
Next, you need to ajaxify the form so it submits through AJAX. I do this through hook_form_alter, so we can set a unique wrapper on the form using the #build_id, which is not available in the original form definition. This allows your form to be used multiple times on the same page if you ever need to.
In the above block of code, we set the ajax callback to form_popup_form_ajax_callback(). The next thing to do is to register a command that will execute your popup in this ajax callback.
Finally, we will look at form_popup.js, which we added to the form in the first step. This is where we will add our command that will execute the popup. We need to create the callback for formPopupTriggerPopup that we set as a command in our ajax callback.
form_popup.js
And there you go. Now the entire form is ajaxified, and when it is submitted, the submitted value is passed to your javscript, allowing you to create a popup that contains the submitted value.
For more information on calling JS after an AJAX submit see this tutorial I wrote: http://www.jaypan.com/tutorial/calling-function-after-ajax-event-drupal-7
webform
It works for me too by forms, but I would love to achieve it by a webform. Do somebody know the workaround?
My code looks like this now:
If instead my webform I render here your form, it's works, if the '$form['submit'] = array...' part is by the defining of the form (as in your original code).
Hai
Hai
This code is working popup will come, but does not bother about validation case. Actually popup will come after the validation only, but here popup come first then only goesto the validation case
You can solve that by doing
You can solve that by doing this:
Hai Jaypan,
Hai Jaypan,
Thank you for your reply .This code be solved my pblm .Now checking the validation case.
Wow.
This is an impressive answer. It was very helpful to me.