Hi,

Since the submission Webform content is stored in a database, is it possible to use the information submitted in the database in a node?

If so, does anyone have ideas on how that might be done?

Thanks!

Comments

quicksketch’s picture

You can pull data out of webform by using the PHP function webform_get_submission(). However, if you're asking if a webform submission can be a node, absolutely not (there's a note about this on the project homepage).

martenw’s picture

Thanks quicksketch! Yeah, I saw that note too, that was not what i was going for...i could probably use webform_get_submission().

Now all i have to do is learn how to use it properly. If anyone thinks it sounds like fun to post a code snippet example, i would be most grateful!

Until then, i'll just keep trying!

martenw’s picture

Let me correct that: I will not keep trying! too little knowledge, too little patience!

So let me instead put it this way: Suppose i have a webform with a textfield called "name". What code would i have to put into a page node in order for it to show the data in "name".

Thanks in advance for any help, it's much appreciated!

quicksketch’s picture

Something like this (totally, totally untested):

$node = node_load(arg(1));
$sid = 10; // Or whatever submission you need to load.
$cid = webform_get_cid($node, 'name', 0); // Replace "name" with whatever your field key is, this only works for fields at the root level (no fieldsets).
$submission = webform_get_submission($sid);

print $submission['data'][$cid]['value'][0];
martenw’s picture

If if could send you flowers...

Even if it's untested, now i have something to work with! Thank you so much!

martenw’s picture

I got a white screen with this message:

Fatal error: Call to undefined function webform_get_submission()

Since it looked like webform_get_submission() was defined in "webform_submissions.inc", i tried adding this to the code:

function webform_menu_submission_load($sid) {
  include_once(drupal_get_path('module', 'webform') ."/webform_submissions.inc");
}

But then i got this message instead:

Fatal error: Cannot redeclare webform_menu_submission_load()

Any suggestions?

quicksketch’s picture

Status: Active » Closed (fixed)

I'm not able to provide further help on this issue. As no one has posted in several months, I'm closing the issue.

saml’s picture

martenw, (message #6)

I managed to load webform submissions. I did it in the webform-confirmation.tpl.php, (which is used to create custom confirmation messages) so I had access to the variable $sid (submission id) and $node->nid which is automatically the nid of the actual webform, since I'm staying at that node when writing out the confirmation message. But I guess the method works quite generally, except for that you'll need to get the sid and nid values somehow.

I loaded the submitted data using the following code:

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

Hint for non php-developers: Use the following code to see how to retreive the data you're interested in:

print_r($temp_submission);

(More hints for non php-devs): $temp_submission, when using the first line of code above, 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. For example, I retreived the content of an e-mail field (which was field no 2 in my form) like so:

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

Hi,
WOuld be great to be able to get some of the info from the webform submission inside say a weblinks node.
Subscribing, while this thread is leading to something right?
greetings,
Martijn

nnevill’s picture

before using webform_get_submissions()

you need to include:

include_once(drupal_get_path('module', 'webform') ."/includes/webform.submissions.inc");

it's for 3rd version, biu i think for 2nd it must be similar