4

How can i print/echo the submitted value of specific field in from a webform? I need to do this in the webform 2 PDF module so i can better customize the output of generated PDFs. Im fairly new to Drupal so an example of how to get a simple f_name filed would be great.

I'd also like to start getting more involved with the Webform API too.

i.e

First Name: SUBMITTED NAME VALUE

2

In recent 3.x and 4.x versions of webform it has an hook based API to allow you do stuff with submitted webform values.

Look at like hook_webform_submission_insert() or hook_webform_submission_update() (if your webform has Drafts enabled for instance the final submission is an UPDATE call with isNew == False and isDraft == False).

The functions take a parameter $submission that is a PHP array of the submitted form values ... You can do whatever you want with them from there.

| improve this answer | |
  • Correction: The $submission parameter is a stdClass object, not an array. – tvanc May 6 '14 at 16:02
2

To get webform values right after the page submit, they're stored in the global $_POST variable.

Alternatively you need to load the right webform submission.

Drupal 7

Here is example how to do it in Drupal 7 (as per this post):

module_load_include('inc', 'webform', 'includes/webform.submissions');
$submissions = webform_get_submissions(array('nid'=> 123));

foreach ($submissions as $submission){
    foreach ($submission->data as $row=>$data){
        print '<pre>'; print_r($row); print '</pre>';
        print '<pre>'; print_r($data); print '</pre>';
    }
}

Drupal 8

Here is the example to get the webform submission in Drupal 8:

$entity = \Drupal::entityTypeManager()->getStorage('webform')->load('my_webform');
$form = $entity->getSubmissionForm();
$elements = $form['elements'];

Here is the example using drush:

drush ev 'print_r(\Drupal::entityTypeManager()->getStorage("webform")->load("repairs_taps")->getSubmissionForm()["elements"]);'
| improve this answer | |
1

In Drupal 5-7 it looks like one can use the webform_get_submissions function.

| improve this answer | |
0

Drupal 8 solution:

$entity = \Drupal::entityTypeManager()->getStorage('webform')->load('my_webform');
$form = $entity->getSubmissionForm();
$elements = $form['elements'];

At the moment there is no function webform_get_submissions() in Drupal 8 (as exists in D7 and D6). Above lines can help to get the submissions of a specific webform.

| improve this answer | |

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.