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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

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).

chertzog’s picture

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.

quicksketch’s picture

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.

cainrus’s picture

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

cainrus’s picture

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

cainrus’s picture

Status: Active » Needs review
FileSize
3.06 KB

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

quicksketch’s picture

@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.

chertzog’s picture

Category: support » feature
FileSize
2.54 KB

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.

chertzog’s picture

oops. double post.

cainrus’s picture

Good one, chertzog.

quicksketch’s picture

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.

firfin’s picture

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.

firfin’s picture

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

cainrus’s picture

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).

firfin’s picture

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

quicksketch’s picture

Title: Access submission data tokens » Access submission data tokens from earlier pages in markup components
FileSize
2.84 KB

Clarifying title. I tested out this patch and revised it so that loading things out of $form_state['args'] isn't necessary. This approach makes it compatible with Form Builder. However in testing I couldn't get my tokens to replace properly, so something must be amiss yet. I'd consider this an in-progress patch that shouldn't be used in production. It moves things towards where I'd like this issue to be but something isn't working with my approach.

quicksketch’s picture

Status: Needs review » Needs work

Moving to needs work per #16.

drubin’s picture

This seems like a feature worth having in 4.0. How much would it cost to sponsor the completion of this feature?

lifeontheshore’s picture

Issue summary: View changes

This is a great feature! What would have to be changed in the above code to make it work in a textarea?

My goal is to ask several story questions and then have those answers auto populate a textarea where the kids can make edits to their story as a whole before submitting.

I used the above code to enable these tokens in markup and that worked wonderfully, but I don't want them to have to copy & paste markup into the final textarea. I have tried making minor tweaks to get these tokens working in textarea.inc, but my php is not so strong just yet, so I'm not having much luck.

firfin’s picture

Status: Needs work » Needs review

@quicksketch : What tokens aren't being replaced? It is working perfectly for me with Webform rc4 (and the patch from #16). Maybe some other (related) issues were solved in the meantime?
I think this warrants at least some more testing instead of 'needs work'?

Using [submission:values:p1_text1] style tokens, where p1_text1 is the field key of course. I do have token module ( version 7.x-1.5) installed though. Without the patch it doesn't work however.

@lifeontheshore : Let's get this in for markup fields first? Then afterward maybe open a new issue to get it in textfields? Not quite sure why you would want this (end users using tokens?) But like I said probably better to discuss this in a new topic?

The last submitted patch, 8: 1672890-access-submission-tokens.patch, failed testing.

The last submitted patch, 9: 1672890-access-submission-tokens.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 16: webform_markup_submission_tokens-1672890.patch, failed testing.

lifeontheshore’s picture

@firfin No, I don't want users entering tokens themselves, I'd like the tokens to pre-populate a textarea something like a default value.

Example:
Page 1- Question - "Who is this story about?" - Next
Page 2- Question - "What did they do in the morning?" - Next
Page 3- Question - "What did they do in the afternoon?" - Next
Page 4- Question - "What did they do in the evening?" -Next
Page 5- Question - "What did they they learn that day?" - Next
Page 6 - Review - using tokens, display the above answers all together as kind of a story, but ready for a final edit before submitting.

In markup, with a text area below, one has to copy the markup and paste it in the text box, then make final edits, then submit. For young children and grandparents, Copy & Paste can be problematic.

I would love to have the tokens pre-populate a textarea instead of a markup area. Then people could just edit the whole story right in that one textarea without the need to copy & paste. Simplicity is key :)

I didn't make a separate issue since it seemed to fall under the same functionality ( as per #7? ) but I would be happy to open one if it would make the difference.

DanChadwick’s picture

@lifeontheshore -- Tokens should work fine as a default in textareas in 7.x-4.x. This issue applies only to markup components.

CORRECTION: [submission:value:FORMKEY] tokens are not available as defaults currently.

adanielyan’s picture

Dan, unfortunately tokens do not work for me on textareas as a default value. I have a clean Drupal 7.31 installation, Webform 7.x-4.1 and Token 7.x-1.5.

I have a webform with two pages. On the first page I have a text field with text_one key. On the second page I have a textarea with default value set to [submission:values:text_one:nolabel]. However the textarea remains blank after filling in the text_one field on the first page and clicking Next.

Any suggestions?

adanielyan’s picture

I would appreciate if someone can confirm that the described setup either works or doesn't work for you. That may help me to debug the problem.

DanChadwick’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#2352373: Set component values based upon tokens and/or other conditional values

Closing as a duplicate, even though there is code here. Same-page issues make this a complicated issue.

jasonawant’s picture