I'm using the session to pass data from a node to my webform (sounds bad, but it really isn't) and I've nested all of my data like so:
$_SESSION['registration']['nid']
$_SESSION['registration']['class']
$_SESSION['registration']['date']
On my webform, I've set the default values of those 3 respective hidden fields to:
%session[registration][nid]
%session[registration][class]
%session[registration][date]
When looking at the page source the value of those 3 hidden fields are:
nid
class
date
If I move my data up to the top level of the array like: %session[registrationNID] etc etc the webform will work correctly and as an example the hidden fields contain the actual values:
45
Tennis 101
Aug 24 2010 to Sept 27 2010
Comment | File | Size | Author |
---|---|---|---|
#13 | nested_tokens-824606-13.patch | 1.58 KB | Deciphered |
#12 | nested_tokens-824606-12.patch | 1.58 KB | Deciphered |
#6 | webform-arraytokens-824606.patch | 1.63 KB | rschwab |
Comments
Comment #1
devkinetic CreditAttribution: devkinetic commentedI have a feeling that the issue has to do with line 2319 of webform.module, but I don't know enough about the module to do any real damage to this issue.
Like I said before a workaround would be to store your data at the top level of session, but that isn't always an option and it's not neat.
Comment #2
quicksketchI haven't been able to find the issue, but I know this has been raised a few times before. I wouldn't qualify this as a bug though, since Webform doesn't claim to work with arrays at all.
Comment #3
devkinetic CreditAttribution: devkinetic commentedFair enough. I was able to modify my code to effectively work without the array, and if you point me in the right direction, I'll take a look at this on my own time.
In case anyone is interested, here is a simplified way of dealing with not having an array to organize:
Comment #4
m-patate CreditAttribution: m-patate commentedHi,
I face the same issue with my webform.
Finally, I decided to code it.
Unfortunately I don't know how to build a patch.
As said #1 the hack was near to this code (beginning at line 2793) :
I add this recursive function to build all the replacements (the function name should not be accurate) :
It works for all tokens with array values (%get, %post, %session - my case too -, ...) : for example %session[registration][nid], %session[registration][class], %session[registration][date] will return values.
Awaiting your feedback
Comment #5
quicksketchThere is a handbook page at http://drupal.org/patch/create that might help move this request forward.
Comment #6
rschwab CreditAttribution: rschwab commentedMany thanks to pef for starting this off. I've adapted #4 slightly and posted a patch. It definitely needs work before its production ready though, for example object support. However, its already doing the job for replacing form values in $_POST.
Comment #7
westie CreditAttribution: westie commented#6 Works nicely for me on d6, thank you rschwab. Was there any code that is d7 specific I might have missed?
Would be nice to have this included in webform as supporting %session but not arrays seems kinda strange considering most things stored in session are put into arrays for great organisation etc.
Comment #8
SNaKeMe CreditAttribution: SNaKeMe commented#6 Works nicely for me on d7, thank you rschwab.
Comment #9
anou#6 patch works like a charm, at least on %post token. Didn't test other cases. Thanks to rschwab.
EDIT: I'm using webform 7.x-3.18
Comment #10
nplowman CreditAttribution: nplowman commented#6 patch works for me if the value is initialized. I was running into a problem though if an array key was not set. For example, if I set the default value as %session[foo][value], but value had not yet been set it would print "[value]" into the field rather leave it empty. Probably a quick fix if someone has the know-how.
Comment #11
sammys CreditAttribution: sammys commentedEDIT: Deleted.
Comment #12
Deciphered CreditAttribution: Deciphered commentedI've updated the patch to improve the coding standard, but nothing other than that as it works as needed for my usecase.
As an aside, the patch also applies and works on the 6.x-3.x branch.
Comment #13
Deciphered CreditAttribution: Deciphered commentedDamn, missed one.
Comment #14
sammys CreditAttribution: sammys commentedI still believe this patch needs some work because while it works correctly for the initial submission it doesn't work correctly when the form is updated by an admin.
The use case I used was quite simple. First name and last name text fields along with a secure hidden field with the default value set to
%post[submitted][first_name] %post[submitted][last_name]
.Initial submission works perfectly and the value bubbles through to a configured email correctly. Unfortunately, editing the form submission and submitting it again does not change the full name field.
I think this bug will need to be ironed out before this patch can be considered for commit.
Comment #15
DanChadwick CreditAttribution: DanChadwick commentedAt this point, 7.x-3.x is receiving critical bug fixes only. Please update to 7.x-4.x.
Comment #16
rschwab CreditAttribution: rschwab commentedJust as an FYI this is now supported in 7.x-4.x. See #1840738: %profile[key] token does not work