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.



4 Answers 4


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"]);'
  • This is no longer the best way for Drupal 8+. It should be $entity->getElementData($field_name), or $entity->getData() to get all the data.
    – mbomb007
    Commented May 16, 2023 at 17:16

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.

  • Correction: The $submission parameter is a stdClass object, not an array.
    – tvanc
    Commented May 6, 2014 at 16:02

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


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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