How to add the Submission Number to the Confirmation Message of a Drupal Webform Submission

When a user is submitting a form it would be nice to give them a tracking number. In order to do this it might be necessary to load the submission tree in code and locate the submission id. It is not otherwise available as a substitution token. There is an alternative. Since the submission URL contains the submission ID you can use a little PHP code to extract the submission ID ($sid) from the URL and display it in your text. This does require ‘PHP code’ Input format access and you have to select PHP code as the input format on the confirmation message. Here’s a sample snippet of code to display the submission number.

Your submission number is <?= $_GET['sid']; ?>.

You can format the message using the drupal_set_message function to set it above and apart from the rest of your submission page text. It will be rendered according to your current theme.

<?php drupal_set_message(t('Your submission number is '. $_GET['sid'])); ?>

Here’s another example that is compatible with i18n internationalization module if you need to localize your submission for other languages.

<?php print t('Your submission number is: '. $_GET['sid']) ; ?>