I've got my Webform to work nicely with the Simple Dialog. Thanks for this great little module which is very simple to use.

When the Webform is submitted, the confirmation URL is displayed in the original browser window from which the Simple Dialog was launched. I would prefer the confirmation URL to be displayed in the Simple Dialog window instead.

#1196150: Example to display webforms (webform.module) within CTools modal windows gives a description of how this can be achieved using Ctools. Is something similar possible with Simple Dialog?

Comments

drclaw’s picture

Category: support » feature

Currently there is nothing built into simple dialog to put the confirmation directly in the dialog window. Although, it is something I've been thinking about building into it. I would like it to be simpler than the solution in the link you provided. I've changed the ticket type to 'Feature Request' and I'll try to sit down with this sometime soon to see how I can streamline this process.

lock2007’s picture

Is there a method to focer open the page after posting (ie in the
).
in other words: I am in the page that it openend with simple-dialog when I click submit, I send the parameters to the page (that is in the "action" attribute of
tag) to open it also in a simple-dialog?

drclaw’s picture

There is no method currently to open the confirmation page within the modal. I am working on it though.

mgladding’s picture

I am looking for something similar. Is there away to show the error messages inside the modal?

Thanks in advance for any help!

drclaw’s picture

I've looked into this one a bit more since the issue was originally posted. It's a little trickier than I originally thought. The best solution is probably to use a ctools modal window and some form of the method described in #1196150: Example to display webforms (webform.module) within CTools modal windows. Because of this, however, it might take me a little while to get it working in this module (of course patches are welcome!)... Although I'm now wondering if this is better suited for a different module since this one is really just a simple implementation of jquery ui dialog, whereas the webform thing would be a ctools modal implementation... any thoughts?

carvalhar’s picture

Hi,

I have a webform with Webform Validation and it opens inside Simple Dialog and everything occurs (ok and error messages) inside the dialog =)

I had to do some changes in webform configuration, tpls and a javscript (inside my theme).
Here's my solution:

1- Simple Dialog button configuration:
<a class="simple-dialog" href="MY_URL" name="node-MY_WEBFORM_NID" title="Webform">Open</a>

2 - Webform configuration
At your webform configuration (node/MY_WEBFORM_NID/webform/configure), chose to redirect to the same node url (eg. node/MY_WEBFORM_NID) . With this you always force to have a html id for the main div presented in node.tpl (eg.: div id='node-MY_WEBFORM_NID'). This id was used as 'name' in Simple Dialog button. Also you should add a confirmation message to be shown upon successful submission.

3- TPL theming
Drupal messages (validation errors or sucessful submission) exists only at page.tpl but i need to print them on node.tp, inside the main div. So you need to make this variable global at page.tpl and print it in node.tpl. Add these two codes:
3.a - page.tpl.php:

global $global_messages;    
$global_messages = $messages;

3.b - node.tpl.php:
<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>>

global $global_messages;
print $global_messages;
print render($content);

</div>

3- Javascript (jQuery/Ajax)
Add a similar javascript code o your theme javasscript file:

$("form#webform-client-form-MY_WEBFORM_NID").find('#edit-submit').live("click", function(){
	var urlform = $("form#webform-client-form-MY_WEBFORM_NID").attr('action'); 
	$.ajax({  
		type: "POST",  
		url: urlform,  
		data: $("form#webform-client-form-MY_WEBFORM_NID").serialize(),  
		success: function (data) { 
			$('#simple-dialog-container').html($(data).find("#node-MY_WEBFORM_NID"));
		}
	});
	return false;
});

Hope this can help someone else ;)

Bye
Carlos
PS: if inside your modal all the main content can appear again, you won't need to load messages inside node.tpl, you can open directly the main div from page.tpl, but if you do so, you'll have to print everything else, as blocks, title, breadcrumbs...

sakadava’s picture

Hi Carlos,

Your post #6 worked well for me and I really appreciate your feedback on this issue.

I am using the Omega theme so this had to be adapted slightly. For example $messages are already in the right place and I changed:

$('#simple-dialog-container').html($(data).find("#node-MY_WEBFORM_NID"));

to

$('#simple-dialog-container').html($(data).find("#zone-content"));

I also added a formatter and automated the generation of the Javascript in a custom module so the administration interface can be used to configure the popup.

drclar: I'm leaving the original issue open as a feature request for now because I think it could be useful to integrate nicer Webform functionality into Simple Dialog. However Carlos's suggestion has resolved this for me, so leave open or close as you see fit.

Simon

elianhi’s picture

Carlos,

Your code worked for me. But a question: the form is rendered again. Is it possible to only show the confirmation message?

Thanks,
Elian

sakadava’s picture

Hi Elian,

Like you I didn't want the form rendered again so I simply set the webform redirection location to a custom URL and this worked just fine, after ensuring the container for the custom content was specified correctly in this statement:

$('#simple-dialog-container').html($(data).find("#zone-content"));

Hope that helps,
Simon

carvalhar’s picture

You both need to pay attention if the form isn't validated...
Aren't you using any kind of validation? If you aren't, it's safe to redirect to other page.
But if you are, you'll need to display the form again. Because sometimes the user will type an incorrect email for example, and the message will point him to edit the email field and no webform is sent until validation is fine.

sakadava’s picture

Hi Carlos,

Thanks for following this up. This does seem to work fine. When form validation fails, the form is redisplayed in the popup along with the associated message. When form validation succeeds, the redirected page is displayed in the popup.

Previously I was dealing with this using Ctools and a form built in a custom module, but being able to do this using Webform and your mechanism really helped, so thanks again.

Simon

carvalhar’s picture

nice, i didn't try this before.
In my case i had to add a nofollow to robots to avoid search mechanisms indexing the 'thank you' page.

drclaw’s picture

Status: Active » Closed (fixed)

This isn't something that is easily done and is probably outside the scope of a "simple" dialog. The solution in #6 is pretty good in the interim but requires you to write your own javascript which kind of defeats the purpose of this module. If you know how to do a jQuery ajax call, you may as well script your own dialog as it could be more flexible and possible perform better. =)

gerrit1978’s picture

this one saved my life :)

Teresa_’s picture

I hope it is okay to continue this thread since it is old but I would really like to talk with someone who has more experience with this. I have this working with Omega and #6 solution but I am finding it writes to the webform results database twice. I took my extra validation module out because I thought it was contributing to the issue. Need help putting that back in and stopping the errant POST from my custom module. But lets start with why this code rewrites to the database.

 $("form#webform-client-form-143").find('#edit-submit').live("click", function(){
var urlform = $("form#webform-client-form-143").attr('action');
$.ajax({ 
type: "POST", 
url: urlform, 
data: $("form#webform-client-form-143").serialize(), 
success: function (data) {
$('#simple-dialog-container').html($(data).find("#block-system-main"));

}
});
return false;
});

Thanks
Teresa_

drclaw’s picture

Hi,

My guess would be that the click event handler is being attached twice to the button. Is your code in a Drupal.behavior? You could try using jQuery once to ensure the click handler only gets applied once.

Alternatively, have you tried Modal Forms? It works quite well with webforms. It might work for you.

drclaw

Teresa_’s picture

It had something to do with the validation. Didn't try Modal Forms but I am very fond of Webform. I am still trying to figure out the array that defines the order of events on the form submission. This is critical to getting the validation in the right place and not logging in the db twice.

Thanks,
Teresa

drclaw’s picture

Just to clarify, Modal Forms works with webforms. Your existing webforms don't have to change. You would just create the links that launch the modal differently. Here's the documentation

Teresa_’s picture

Once I catch up I want to try a side by side comparison to see if modal forms is faster than my solution. I find there is a little hesitation with simple dialog. Thanks drclaw.!

Teresa_’s picture

Issue summary: View changes

Fixed format of referenced issue