i was searching and reading all issues and forum topics, tried a lot of available code but no success.
seems that functions logic is not very clear for me, which is ok as i am not a php developer.

anyway, my goal is to display form results upon submitting in printable way, i.e. user is able to print just submitted form.
i found some solution in mail formatting but i really need to format text in different way (since huge number of form fields and specific theme ...) .
so, if i would know to return and display single value i could do it with all the rest and will be able to format/display it in required way.
also, for example _webform_submission_format function doesn't display values of file field (upload) and i would like to display name of the uploaded file (doesn't have to be download link, just displayed file name) ...

any suggestions and help would be much appreciated, thanks !
here is the latest code i tried to put in additional processing to get just email field name and value, no success :(

foreach ($form_values['submitted'] as $field_id => $value) {
  $component = $node->webformcomponents[$field_id];
  if ($component['name'] == "email") { 
   $email = $value;
   $out = $component['name'] . ":<b> " . $email ."</b>";
}
}
print($out);

Comments

Critical Tinkerer’s picture

There seems to be no proper treatment of the tags "Additional Validation" and "Additional Processing" in any documentation. I, for one, would like to see some sample code that does just this sort of thing and a whole slew of other things.

The module itself says:

Enter PHP code to preform additional validation for this form. Include the < ? php ? > tags. $form_id and $form_values are available variables. If validation fails, use the form_set_error function to prevent the form from being submitted. Use the same syntax as a _validate function used in the Forms API.

This doesn't help anyone just getting started. How about a handbook on advanced WebForm usage?

quicksketch’s picture

quicksketch’s picture

Some useful issues:

Advanced validation and submission code: http://drupal.org/node/81761
Setting custom confirmation messages/pages: http://drupal.org/node/131396

quicksketch’s picture

Title: i must be very dumb! but please let me know how to display submitted single field value on confirmation page » Display submitted field value on confirmation page
quicksketch’s picture

I figured this out today by accident and I thought I would share the solution.

Use the following PHP code as the Confirmation message for your webform:

$node = node_load(arg(1));
print node_view($node, FALSE, FALSE, FALSE);

This will print out the display of the submission on the confirmation page.

seakayjay’s picture

I'm looking forward for this as well. Instead of display of submission, is there anyway to display a single field value only on the confirmation page?

Regards

john.money’s picture

tag for later... I've got some examples and if I can find the time between projects to write them all up, I will. To get you started, here is some code I used just tonight that will throw an error if two email fields email_address and email_verify are not the same:

<?php
if ($form_values['submitted_tree']['email_address'] && $form_values['submitted_tree']['email_verify'] && $form_values['submitted_tree']['email_address'] != $form_values['submitted_tree']['email_verify']) {
  form_set_error('', t('Please verify that you have entered your email address correctly.'));
}
?>
FredJones’s picture

I'm looking forward for this as well. Instead of display of submission, is there anyway to display a single field value only on the confirmation page?

I also want this, to be able to style the output and show the user the data he inputted. I see no way except via PHP/MySQL. You would have to parse the URL to get the sid # and then extract the submitted values from the webform_submitted_data table using that sid.

Quite a roundabout way however...

FredJones’s picture

Just in the event that anyone is really reading this, I do now see that you can also get the sid value from $_REQUEST. Try

print_r($_REQUEST);

and see. :)

OK, I am done. I just coded a custom contact us page in plain old PHP and it shows the data inputted by the user very nicely. Simple, yet works perfectly.

rick hood’s picture

The code mentioned above works great:

<?php
foreach ($form_values['submitted'] as $field_id => $value) {
  $component = $node->webformcomponents[$field_id];
  if ($component['name'] == "email") { 
   $email = $value;
   $out = $component['name'] . ":<b> " . $email ."</b>";
}
}
print($out);
?>

My problem comes when the form element is a multiple choice check box (multiple selections allowed). The $value then seems to be an array and so what prints is just "array".

I probably need to loop through that array to get the values and concatenate them together?

I'm afraid I either don't know enough PHP and/or Drupal to understand what I need to do this. I know this is probably basic.

Thanks for any advice.

More info:

A print_r ($node) for the actual webform element I am working on looks like this for one of the multiple choice checkbox elements:

 [1179526231] => Array
                (
                    [cid] => 1179526231
                    [form_key] => hinckley_power
                    [name] => Hinckley Power
                    [type] => select
                    [value] => 
                    [extra] => Array
                        (
                            [items] => T29C
T29R
T38R Convertible
Picnic Boat
T40
T44
T44FB
T55
T55FB
POWER - Brokerage
POWER - Do Not Know
                            [description] => 
                            [multiple] => Y
                        )

                    [mandatory] => 0
                    [parent] => 1179530839
                    [weight] => -5
                )

So, say the user chose the first two: T29C and T29R. I would want to those to appear together in the output that prints the submitted value of that element.

I should note that this is NOT for use on the confirmation page, but rather to use these values in an email that gets sent - but either way, I need to grab the values.

quicksketch’s picture

Hey Rick, like you mentioned, if the value is an array, you'll need another loop inside to add all the strings together. Here's an untested attempt at what you might be wanting. Hope this helps!

foreach ($form_values['submitted'] as $field_id => $value) {
  $component = $node->webformcomponents[$field_id];
  if ($component['name'] == "Hinckley Power") {
    $out = $component['name'] .': ';
    foreach ($value as $key => $choice) {
      $out .= $choice ."\n";
    }
  }
}
print($out);
rick hood’s picture

Nate - thanks a lot - that worked!

But I don't fully understand why it works. The part that gets me lost is in this line:

<?php
foreach ($value as $key => $choice) 
?>

where I don't fully understand what these are: $value, $key and $choice.

My guess is:

$value is an array, because this form element is multiple-select, unlike the other single-select form elements where $value is just one number or string.

$key is the key of the array - OK so far so good I guess...

$choice is the value of each key - but why $choice? I don't understand how one knows that $choice the the variable to use here.

And in the first foreach statement:

<?php
foreach ($form_values['submitted'] as $field_id => $value)
?>

It's a mystery to me how one knows to use $form_values['submitted'], $field_id and $value - as those are not things you see by just doing a

<?php
print_r ($node)
?>

This is the kind of situation where I get stuck with Drupal, and I need to somehow get better at that as it seems key to really understanding Drupal.

But anyhow - thanks so much for your help!

zaphod280380’s picture

Sorry but i can't understand where i have to put this code (i additional processing field) and how to change it with my form name. Help!

foreach ($form_values['submitted'] as $field_id => $value) {
  $component = $node->webformcomponents[$field_id];
  if ($component['name'] == "Hinckley Power") {
    $out = $component['name'] .': ';
    foreach ($value as $key => $choice) {
      $out .= $choice ."\n";
    }
  }
}
print($out);
zaphod280380’s picture

Sorry but i can't understand where i have to put this code (in additional processing field?) and how to change it with my form name. Help!

foreach ($form_values['submitted'] as $field_id => $value) {
  $component = $node->webformcomponents[$field_id];
  if ($component['name'] == "Hinckley Power") {
    $out = $component['name'] .': ';
    foreach ($value as $key => $choice) {
      $out .= $choice ."\n";
    }
  }
}
print($out);
quicksketch’s picture

Assigned: nk_ » Unassigned
Status: Active » Closed (fixed)

Closing to clean up the issue queue.

drein’s picture

I'm not a programmer, and I'd like to have a sort of reports or data printed when the user click the confirm button.
I don't understand what code should I insert... I tried copy/paste some codes of this thread but no lucky...
any help?

fido100’s picture

This doesn't seem to work in Drupal 6.5 and the latest version of webform. Do you have updated code that would work?

I am trying to implement a system whereby I can pass simple variables such as first_name and last_name to an ecommerce service. I thought this might be an easy thing to accomplish but I can't get anything to show up on the confirmation page.

With thanks
James

jtjones23’s picture

Version: 5.x-1.2 » 6.x-2.3

I'd also like to show the results of a webform submission to the user. The code from #5 displays the form but not the input.

Drupal 6.8
Webform 6.x-2.3

saml’s picture

I managed to display the submitted data on the confirmation page now (Drupal 6, Webform 6.x-2.6).

I followed the instructions in modules/webform/THEMING.txt to copy the file webform-confirmation.tpl.php from modules/webform to my theme folder.

Then, inside that file, I use this code to load the submitted data from the database:

$temp_submission = webform_menu_submission_load($sid, $node->nid);

($sid (submission id) and $node->nid are available in this context.)

Then I used the following to see how to retreive the values I was interested in:

print_r($temp_submission);

Note: $temp_submission will be an object, not an array, so the first level of elements that you see in the tree outputted by print_r is variables in that object, and are accessible with the "->" syntax. So, to use the content of an e-mail field (no 2 in my form) in a message, I used:

echo "A confirmation has been sent to " . $temp_submission->data[2]['value'][0];

Hope this helps.

sunchaser’s picture

good stuff.
is this still valid code for versions 3.x ?

meerkat’s picture

Yes.

todderasesareddot’s picture

function my_node_form_submit($form, &$form_state)
{
    //show the current values of the form
    drupal_set_message('<pre>'.print_r($form_state, TRUE).'</pre>', 'status', TRUE);

    //show the form
    drupal_set_message('<pre>'.print_r($form_state, TRUE).'</pre>', 'status', TRUE);
}

syntheticMedia’s picture

Im happy to report #19 works well with 6.3, thanks for the tip.

vj2150’s picture

Issue summary: View changes

#19 works for 7.57 as well. Thank you. Your post is helpful for newbies like me.