2

I'm using the Webform module's block on a custom content type.

The webform has some text fields and I passed some data from my custom content type fields to webform fields as explained here.

I'm also using the Webform Ajax module for webform submission.

What I want to do is to print some field data from the current node after webform (successful) submission.

I tried to use the webform-confirmation-2.tpl.php to do what I want (2 is the node id of webform):

Method #1

At first, I tried the method explained here:

<?php
  // Print the webform submission to the submitter
  include_once drupal_get_path('module','webform') . '/includes/webform.submissions.inc';
  $submission = webform_get_submission($node->nid, $sid);
  $email = NULL;
  $format = "html";
  print webform_submission_render($node, $submission, $email, $format);
?>

It didn't work.

(Notice: include() (../webform-confirmation-2.tpl.php line: 37) Array to string conversion.)

line 37 is: print webform_submission_render($node, $submission, $email, $format);


Method #2

And another code in the same page didn't work:

<?php
    //lets see if we can show them their submission
    $sid = $_GET['sid'];
    if(isset($sid)){
        include_once drupal_get_path('module','webform') . '/includes/webform.submissions.inc';
        $submission = webform_get_submission($node->nid, $sid);
        $email = NULL;
        $format = "html";
        print render(webform_submission_render($node, $submission, $email, $format));
    }
?>

It gives this error: Notice: include() (.../webform-confirmation-2.tpl.php line: 34) Undefined index: sid.

line 34 is: $sid = $_GET['sid'];

EDIT: I solved the error, it doesn't give an error now but also doesn't give the wanted result.


Method #3

Then, I tried to use menu_get_object() in webform-confirmation-2.tpl.php:

<?php
if ($node = menu_get_object()) {
        $print ($node->field_custom_field['und'][0]['value']);
    }
?>

This also didn't work. Nothing printed, no error.


Method #4

I tried to print the field as a block inside of the webform-confirmation-2.tpl.php by using the Field as Block module:

<?php
$block = module_invoke('fieldblock', 'block_view', '7f1bb640a56605ca4ea56453ebf4c759');
print render($block['content']);
?>

That code also didn't work. It didn't print anything.


How to print a field data from the current node after webform (block) submitted successfully without refreshing the page (webform ajax)?

Maybe another way to do that is to hide the fields (via CSS, JS etc.) at first and then if the webform submission done show them. Here, I have to know the trigger to use in the JavaScript but don't know.

  • Any suggestion? – herci Aug 6 '15 at 17:35

Your Answer

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

Browse other questions tagged or ask your own question.