I will like to display the form result(submit the form to itself, wrapped in a hidden div) within the block itself(as well as the same page), instead of it redirecting to something like node/%webform/done?sid=?.

I tried overriding the hook_form_alter or hook_form_FORM_ID_alter, but it seems these functions cannot be overriden in the theme level, unless it is implemented by another module.

In my implementation anyway, I tried using the AHAH form type, so that the path attribute calls the drupal_get_destination() function, and the wrapper attribute updates a div.

function custommodule_webform_client_form_alter(&$form, &$form_state) {
if($form_id == 'webform_client_form') {
$form['wrapper'] = array(
'#prefix' => '<div id=feedback-result',
'#suffux' => '</div>',
);

$form['wrapper'] += _webform_confirmation($node);

$form['#submit'] = array(
                          'ahah' => array(
                          'path' => drupal_get_destination(),
                          'wrapper' => 'feedback-result',
                          'method' => 'replace',
                          'effect' => 'fade',
                          'event' => 'click'
                              ),
                          );

}
}

Comments

quicksketch’s picture

Title: Make a form result display in a div on the same page » Make form websubmit through AJAX/AHAH
Version: 6.x-2.7 »
Priority: Critical » Normal

I'm not sure I'd recommend this approach, and I certainly don't think it's possible with the current implementation of Webform. It'd probably require a good amount of reworking to get operating properly, especially considering page breaks, file uploads, and the confirmation page.

In the short term, I'd recommend that you just use an iFrame in your block, which will give the appearance of not leaving the page and showing the confirmation in the same place as the form.

quicksketch’s picture

Version: » 6.x-2.7
Category: feature » support
Status: Active » Closed (fixed)
nlambert’s picture

Hi!

The following information doesn't necessarily relate to the Webform module, but it does relate to this issue and proposed solution.

I managed this with the PURL (Persistent URL) module, as I needed a different page template for the iframe.

Here are the different steps

1. Install CTOOLS and PURL

2. create a module and implement hook_purl_provider :

function MODULENAME_purl_provider() {
	return array(
    'My Module' => array(
      'name' => t('my Module'),
      'description' => t('Sets an iframe context'),
    ),
  );
}

3. go to admin/settings/purl and add a "type"
=> in my case I added "Query String"

4. in admin/settings/purl configure your "settings"
=> I added "location" to "key"

5. create a node and insert your iframe

<iframe src="node/1?location=iframe"></iframe>

6. in your module add hook_preprocess_page

if (isset($_GET['location']) && $_GET['location'] == 'iframe') {
		if(!isset($variables['template_files'])) {
			$variables['template_files'] = array();
		}
		$variables['template_files'][] = 'page-iframe';
}

Hope this helps someone