I successfully used this module to submit a "webform" form with a minimum of custom coding.. GREAT!

It submits ok, but nothing happens after the submit.. I see the "ajax" spinner next to it, so it must be possible to make it aware when the submit is done..
Any idea which callback I should use?

All I want to do is close the form, or at least show a message that it has been submitted.
Thanks

Files: 
CommentFileSizeAuthor
#15 1396272-15_handle_submitted_forms.patch1.61 KBXen
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#11 1396272-11_handle_submitted_forms.patch1.59 KBwojtha
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#10 1396272-10_handle_submitted_forms.patch1.6 KBXen
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#8 1396272-8_handle_submitted_forms.patch1.84 KBwojtha
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#5 1396272.patch1.08 KBdouggreen
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]
#3 1396272.patch985 bytesdouggreen
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

Comments

Component:Documentation» Code
Category:support» feature

Its not possible at the moment, so this is a feature request.

I've extended the CTools Automodals so now they knows how to handle submitted forms. You can try my patch here: #1420534-1: Consider a new hook - hook_modal_paths() rather than using hook_menu()

Or just replace ctools_automodal_get_form() with this code:

<?php
/**
* Display a Drupal form using CTools modal or normal page display.
*/
function ctools_automodal_get_form() {
 
$args = func_get_args();
 
$form_id = array_shift($args);
 
$js = $ajax = array_pop($args);
 
ctools_automodal_fix_get_q();
 
// Load modal options.
 
$modal_options = ctools_automodal_get_path(current_path());
  if (
$ajax) {
   
ctools_include('modal');
   
ctools_include('ajax');
   
ctools_add_js('ajax-responder');
   
$form_state = array(
     
'ajax' => $ajax,
     
'build_info' => array('args' => $args),
    );
   
$commands = ctools_modal_form_wrapper($form_id, $form_state);
    if (empty(
$commands)) {
     
$commands[] = ctools_modal_command_loading();
      if (!empty(
$_GET['destination'])) {
       
$commands[] = ctools_ajax_command_redirect($_GET['destination']);
      }
    }
   
// Handle submitted form.
   
if (!empty($form_state['executed'])) {
     
$commands = array();
     
$commands[] = ctools_modal_command_dismiss();
    }
    print
ajax_render($commands);
    exit();
  }
  else {
   
array_unshift($args, $form_id);
    return
call_user_func_array('drupal_get_form', $args);
  }
}
?>

Category:feature» bug
StatusFileSize
new985 bytes
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

Here's the patch to just fix the bug.

Status:Active» Needs work

+++ b/ctools_automodal.module
@@ -126,7 +126,19 @@ function ctools_automodal_get_form() {
+      $commands[] = ctools_modal_command_dismiss(t('Login Success'));

This doesn't seem like a general fix.

+++ b/ctools_automodal.module
@@ -126,7 +126,19 @@ function ctools_automodal_get_form() {
+      if (isset($_GET['destination'])) {
+        $commands[] = ctools_ajax_command_redirect($_GET['destination']);
+      }

Forms are usualy redirected using form_state[redirect] - this should be handled too imho.

StatusFileSize
new1.08 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

You're right on both accounts, sorry, I was copying code from another module.

Status:Needs work» Needs review

Status:Needs review» Needs work

+++ b/ctools_automodal.module
@@ -126,10 +126,21 @@ function ctools_automodal_get_form() {
+      if (isset($form_state['destination'])) {
+        $commands[] = ctools_ajax_command_redirect($form_state['destination']);
+      }

$form_state['destination'] should be $form_state['redirect']. And notice that $form_state['redirect'] can be both array or string.

Status:Needs work» Needs review
StatusFileSize
new1.84 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

Title:Close modal after submitHandle submitted forms

Better title

StatusFileSize
new1.6 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

If $form_state['redirect'] is an array, it is used as parameters to drupal_goto, which means that the second argument is options.

Added support for rebuilding forms, and cleaned up a bit.

Status:Needs review» Needs work
StatusFileSize
new1.59 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

Nice cleanup @Xen!

+++ b/ctools_automodal.module
@@ -126,12 +127,31 @@ function ctools_automodal_get_form() {
+      elseif (is_array($form_state['redirect'])) {
+        list($path, $options) = array_shift($form_state['redirect']);
+      }

However, doesn't seem right to me.

In the drupal_redirect_form documentation is the following code:

<?php
$form_state
['redirect'] = array(
 
'node/123',
  array(
   
'query' => array(
     
'foo' => 'bar',
    ),
   
'fragment' => 'baz',
  ),
);
?>

So it should be:

list($path, $options) = $form_state['redirect'];

(However in this case we still silently suppose that non-mandatory $options array is present.)

Status:Needs work» Needs review

You're right, that was a thinko.

Well, if options isn't set, $options should just be empty... Though the manual doesn't say.

Ok, make that:

<?php
list($path, $options) = $form_state['redirect'] + array(NULL, array();
?>

Then options is always set, and an array (as expected by ctools_ajax_command_redirect) per default.

StatusFileSize
new1.61 KB
PASSED: [[SimpleTest]]: [MySQL] 0 pass(es).
[ View ]

And patch...

Trying to get this to work with forward.module (http://drupal.org/project/forward), but no luck so far.
Submit works, but I get a huge js error (200) afterwards.
When I add an extra submit function to the form, that has nothing but exit(); in it, I don't get the error (but nothing closes)

Any ideas?

I am having an issue with submitting a form as well. I want the form to redirect, however, i don't want it to redirect to the same place each time. Inside of the form submit, i am making a call to a function that takes the form and determines if the person should go to one of two places. Is it possible to do this type of thing? If i try to change the form_state['redirect'] i get ajax errors.

Status:Needs review» Needs work

@rv0 with the patch in #15 it should work. May be you can try my experimental build of this module, see #1420534-4: Consider a new hook - hook_modal_paths() rather than using hook_menu()

@bdawg8569 are you getting Ajax errors with the patch in #15 or without?

@wojtha
I tried the experimental build, but it doesn't work on PHP <5.3 https://github.com/wojtha/ctools_automodal/issues/1

Will also retry #15 on a fresh install.

@rv0:
Does the menu item that you're modalling have 'page callback' => 'drupal_get_form'? Automodal doesn't work well with page callbacks that call drupal_get_form themselves.

@Xen good point

@rv0 if it is that case you can take some inspiration from #1450372: How to: How to handle two forms in one modal (unified login page). I've described there how to handle two forms in one modal window. For live example you can go to http://ecommera.com and click on "Register".

the menu item looks like this

<?php
   
'page callback'    => 'forward_page',
   
'type'             => MENU_CALLBACK
?>

The forward_page function looks like it hasn't changed since D6 as it has some legacy modalframe code in it.
it applies some logic and then returns a result of drupal_get_form
http://drupalcode.org/project/forward.git/blob_plain/HEAD:/forward.module

Then it's really a separate issue. The code this issue deals with determines forms from the menu callback.

Whether there really is a general way of dealing with forms in page callbacks is the question.

Hi,

I've tried patch #15 with a webform having confirmation message set a "No redirect (reload current page)".

The form submits correctly and I can see the throbber. However the confirmation message is not displayed in the modal window after the submission. It is displayed into the background window after a full page reload

Any idea?

Thanks

Laurent

@Laurent, you may try my fork of this module https://github.com/wojtha/ctools_automodal, there you can handle confirmation messages (details here: #1420534: Consider a new hook - hook_modal_paths() rather than using hook_menu())