2

I have created a webform block and assigned to a page in the right sidebar. After successful submission of that block, I want the thank you message with the values submitted in the webform to displayed where block was there before in the same page.

I have given no-redirect option in the form settings of the webform.

Also in the block settings of the webform block given view mode as form only.

But how would I replace the webform block with thank you message on successful submission of webform in the same page? Is there any Drupal way to achieve this. Have I missed any settings ??

Any help will be much appreciated.Thanks in advance.

  • Think what you are searching for can only be solved by code. Just a few questions: Is the thank you page a temp state, or should the user never see the form again? (if no display if onced submitted: is it only for registered users?) – Nugorra May 13 '15 at 14:20
  • After a successful submission of the webform I want to show the thank you or confirmation message in the place where the webform block is instead of that webform.If we refresh the page again the webform will showed again. – Ram May 14 '15 at 3:05
1

If you have the webform set as a block, you can go to admin > structure > block. Look for your webform block. It should be named something like Webform: 'name of webform node'. Click on the configure link to the right. When the edit form for the block loads, look for the section Confirmation message. Select the option Display the confirmation page in the block on the same page (no redirect). Now when you submit the form from the block, it will redirect back to it and show the confirmation message on reload.

You may need to fill out a message in the webform settings. I have attached an image of the edit block page for you to compare.enter image description here

0

This is sort of hacky but I couldn't figure out a way to do it with Webforms natively. This implementation uses a custom module.

// Register custom module block

function my_module_block_info() {
  $blocks = array();
  $blocks['my_form'] = array(
    'info' => t('My Form Title'),
    'cache' => DRUPAL_NO_CACHE,
  );  
  return $blocks;
}

// set block content

function download_training_plan_block_view($delta) {
  $block = array();
  switch ($delta) {
    case 'my_form':
      $block['subject'] = '';
      $block['content'] = my_form_details();
      break;
  }
  return $block;
}

// set block theme

function my_form_details() {
  return theme('my_form_details');
}

// use custom template file.

function download_training_plan_theme() {
  $template_path = drupal_get_path('module', 'my_module_template_file') . '/templates';
  $theme_hooks = array(   
    'my_form_details' => array(
      'path' => $template_path,
      'template' => 'Altered form',
      'variables' => array('title' => NULL),
    ),
  );
  return $theme_hooks;
}

// when webform is used, alter form to include callback function

function my_module_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#node']->title == 'Obstacle Teaser 2018 Data Capture'){
    $form['actions']['submit'] = array(
      '#type' => 'submit',
      '#ajax' => array(
        'callback' => 'my_form_callback',
        'wrapper' => str_replace('_', '-', $form['#form_id']),
      ),
      '#value' => t('Submit'),
    );
  }
}

// set cookie to remember submitted state and show hidden content

function my_form_callback(&$form, &$form_state) {
  if (!form_get_errors() && $form_state['values']['details']['sid']) {    
    // Save cookie.    
    setcookie('is_submitted_cookie', TRUE, REQUEST_TIME + (31556926 * 2), '/');
    $commands = array();
    $commands[] = ajax_command_invoke('#secret_content', 'show'); //show hidden content
    return array('#type' => 'ajax', '#commands' => $commands);
  }
  return $form;
}

// in file: my_module_template_file.tpl.php

        <?php $download_form = module_invoke('webform', 'block_view', 'client-block-999999'); ?> // replace 999999 with nodeID of webform.
        <?php if (!empty($download_form['content'])): ?>
          <?php print render($download_form['content']); ?>
        <?php endif; ?>
<div id="secret_content" style="display:none;"><a href="#">Download content</a></div>
0

Enable Webform AJAX module, install it. To configure:

  • Go to your Webform's Form Settings
  • Check AJAX mode
  • and then check on Show confirmation screen
  • And make sure you select No redirect (reload current page) under Redirection location.
  • Add some text in Confirmation message textarea.

And when you submit the webform you will see Confirmation message instead of the webform.

-1

Goto your Webform Form Setting & add your Confirmation message.

Confirmation message : Put your message in this field.

Redirection location : Check "Confirmation Page"

enter image description here

  • Please read the question once again, I want the confirmation message to displayed at the place where webform block is placed. – Ram May 13 '15 at 13:08
  • I have put this answer as per your query. Please try this once & if you got any issue then comment here. – Nishant May 13 '15 at 13:20
  • It is taking to submission page with this submission url node/167/done?sid=81 – Ram May 13 '15 at 13:25
  • What I want is to display the confirmation in the same page and replace the block and show the confirmation or thank you message at that place – Ram May 13 '15 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.