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.
Hi,
Thank you for this easy to use module. I'd like to a for a way to auto close the modal on user submition if the form doesn't have errors. Can you please provide some advise?
I have search in the web and I get to the ctools_modal_command_dismiss() function but I'm not sure where to put it.
Thank you
Julian
Comments
Comment #1
julianmancera CreditAttribution: julianmancera commentedHi
I have found a solution, it needs this code change in the ctools_automodal.module line 127 function ctools_automodal_get_form:
Please let me know you comments. The other posibility is in the submition function for the form add a form_state['command'] array variable that allows to control wether to close the modal or maintain the user there for further user operations.
Let me know your comments
Julian Mancera
Comment #2
HakS CreditAttribution: HakS commentedHi julianmancera
Unfortunately it does not work for me, form still stays open when submit after applying changes.
I tested it putting this code inside an implementation of hook_menu_alter:
That's the core node add form.
I was trying it on an (almost) clean installation.
Comment #3
HakS CreditAttribution: HakS commentedActually, it seems to work if form is not an administrative form. I created a custom form and it worked, but I don't know if that would be part of this issue, because I noticed that administrative forms on modal windows behave quite strange.
EDIT: If you allow other users to use that modal administrative form (in my case that means allowing anonymous to add articles), when submit an ajax error happens http://d.pr/i/IjA9
Comment #4
Marko B CreditAttribution: Marko B commentedThere is no need for that, you are using it wrong You can do it all with form rebuild and ctools_modal_command_dismiss(); and ajax_render, I also added $commands[] = ctools_ajax_command_redirect(''); so you redirect when you submited a form to a page you want.
Comment #5
Marko B CreditAttribution: Marko B commentedComment #7
capellic@MarkoB, thanks for your code, however I had to add these two module_load_include() calls in order for the ctools_modal_command_dismiss() and ctools_ajax_command_redirect() to be found:
Comment #8
sukh.singh CreditAttribution: sukh.singh commented@capellica, the proper way to add these files are as follow
add this to the function which you are using against the ctools ajax menu link
Comment #9
ongraph CreditAttribution: ongraph as a volunteer and commentedYou can put ctools_modal_command_dismiss(); after successful form submission
Here is coding example of ctools modal auto close with form submission
Comment #10
ugintl CreditAttribution: ugintl commentedThe code from #1 is working, but the page is not updated with the changes automatically. I have to refresh the page to make the changes.