Download & Extend

Access submission data tokens

Project:Webform
Version:7.x-4.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

Is there a way to access submission data from previous fields (ie from previous pages) to display in a markup component?

Comments

#1

I don't think there is currently. If this were implemented, it would probably piggy-back off the existing [submission:values:$key:nolabel] token (where $key is the form key).

#2

Well seeing how after the first page, the submission already has an ID, all we would really have to do is pass the markup components value (or any description value as well) and the submission through token_replace before outputting them to the page if im not mistaken.

#3

Well seeing how after the first page, the submission already has an ID

This is only true if you've enabled the option to automatically save drafts between pages. Otherwise you only have the contents of $form_state['values'] to work with.

If you're interested in supplying a patch I'm happy to review and integrate this functionality. It'd be a good feature, but it's not trivial to implement.

#4

These is very good feature. Do you have anything already? I can help

#5

Here is module. Tested on 7.x-4.0-alpha4.
Module provides new component, type text in it and use tokens.

#6

Status:active» needs review

Here is module. Tested on 7.x-4.0-alpha4.
Module provides new component, type text in it and use tokens.

AttachmentSize
webform_token_component.zip 3.06 KB

#7

@cainrus: Thanks for the code! Ideally I think we'd want to make this functionality of the markup components (and actually other fields descriptions and default values), so it'd probably be better served as a patch.

#8

Category:support request» feature request

Here is a patch to the Markup component, that allows access to token data. I adapted this from the Webform Bonus Pack Summary component. It shouldnt take much more to implement this across any field/description.

AttachmentSize
1672890-access-submission-tokens.patch 2.54 KB

#9

oops. double post.

AttachmentSize
1672890-access-submission-tokens.patch 2.54 KB

#10

Good one, chertzog.

#11

Wow this code does look quite promising! Though it's exploiting some very particular features of Form API (such as using $form_state['build_info']['args'], which is always ugly). Maybe we can/should move the $node object into $form_state['node'] rather than being in $form['#node'], though I have a feeling that'd break a lot of existing code.

#12

After applying the patch in #8 I get the following errors while filling out the form. Using a multipage webform with 4 [submission:values:xxx] tokens on latest page.. The first error appears 4 times on the first pages of the form. The second error appears on the page containing the markup component with the tokens.

This is on a fresh git download of webform ( using
git clone --recursive --branch 7.x-4.x http://git.drupal.org/project/webform.git )

I have cleared caches and ran update.php multiple times.

Am I patching the wrong version of webform?

Notice: Undefined index: storage in _webform_markup_tokens() (line 92 of /home/quickstart/websites/d7dev.dev/sites/all/modules/webform/components/markup.inc).

Surrounding lines from markup.inc:
90: function _webform_markup_tokens($form_element, &$form_state){
91: global $user;
92: $submitted = (object) $form_state['storage']['submitted'];
93: $node = clone $form_state['build_info']['args'][0];

Notice: Undefined property: stdClass::$sid in webform_tokens() (line 81 of /home/quickstart/websites/d7dev.dev/sites/all/modules/webform/webform.tokens.inc).

Surrounding lines from webform.tokens.inc:
78: foreach ($tokens as $name => $original) {
79: switch ($name) {
80: case 'sid':
81: $replacements[$original] = $submission->sid;

Please advise.

#13

Follow up on #12:
My markup component had [submission:sid] in it. Removing this also removes the second error.

#14

Created new sandbox project.
These module is working already 1,5 months with five company sites(There are drupal 6 version and drupal 7 + webforms 3.x version too).

#15

I still have following error message after using the patch in #8

Notice: Undefined index: storage in _webform_markup_tokens() (line 92 of /..../markup.inc).

Also, tokens with the :nolabel modifier do not get replaced.

-- Edit: cleaned up error and added nolabel mention

nobody click here