Closed (duplicate)
Project:
Webform
Version:
6.x-2.9
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
22 Mar 2010 at 19:32 UTC
Updated:
14 Sep 2019 at 14:27 UTC
Jump to comment: Most recent
Comments
Comment #1
spelcheck commentedwebform.module
// Find by form key.
$parents = webform_component_parent_keys($node, $component);
$form_key = implode('][', $parents);
$display_element = webform_component_invoke($component['type'], 'display', $component, $value['value'], 'text');
$replacements['unsafe']['%email[' . $form_key . ']'] = drupal_render($display_element);
$replacements['safe']['%value[' . $form_key . ']'] = isset($display_element['#children']) ? $display_element['#children'] : '';
+ $replacements['safe']['%safevalue[' . $form_key . ']'] = isset($display_element['#value'][0]) ? $display_element['#value'][0] : '';
This might not be the best way to do this, but works for single-value select options.
Edit: if anyone plans on doing this, put some logic in to check whether or not $display_element['#component']['type'] != 'file before the added replacements line, otherwise you will get an error.
Comment #2
quicksketchHm, I'm not sure what to do about this. I think it would be valuable to have access to safe_key values, but I'm not very keen on adding another token. Select lists are pretty much the only component to which this applies, but the intention was to have %value be pretty much the same as %email, only %value doesn't contain the label of the field.
I think it would make sense to always use the safe_key values if the user manually specified them. However, in the next beta of Webform 3, key|value pairs are now required and I intend to simply things down for those that want it through #743428: Add support for Options Element module. Meaning that the safe_key would pretty much always be used. Keys are only automatically assigned if you are using the Options Element module, which hides the keys from the end-user view.
Comment #3
stefan81 commentedHi,
I expected that the safe key is used.
I am looking forward to this feature.
A use case:
In German, the salutation's conjugation depends on the addressee's gender.
So with the safe key I could print the appropriate saluation (a whole sentence) to be followed by the name.
But in the form I only see mr/mrs to keep it lean.
I am not a coder, but I have an Idea, which cauld be easy to handle for users:
A whole new token could be confusing, but why don't simply add a number after the key?
for example [0] is key only, [1] is safe key etc.
Then we even could I define multiple values for a key? key|valueA|valueB
%value[key][1] %value[key][2]
This way I could customize the whole structure of the mail, based on one selection.
For example use "gender" to modify the salutation and then other parts in the mail
quicksketch, thank you for all your efforts and contributions!
Comment #4
quicksketchI'm not understanding your request, is it related to the original issue? It sounds like you're requesting to be able to print out individual options from a select list, which is not the same as wanting to display the safe_key value.
Overall I'm not entirely sure I want to always print out the safe_key when dealing with %value tokens. I'll need to think some more about if we want to do that or not.
Comment #5
stefan81 commentedopened a separate thread for my question: http://drupal.org/node/767898
hi quicksketch,
Thank you for your reply.
Probably I am misunderstanding the purpose of the safe_key.
And I am posting my feature request in the wrong thread.
Will have a closer look at its intended function.
Maybe you can point me in the right direction / thread?
Therefore, I reword my question:
Is there a way to make the text printed in the mail, conditional to a selected value?
Like
with PHP?
Would appreciate some help / instructions.
Thanks a lot!
Comment #6
mikeschneik commentedHow can I get the safe_key into my email?
I want to use a itemnumber as the safe_key.
To copy and paste the Code on Top of this page into my webform.module doesn't work in my Webform3.
(I use Drupal 6)
I only get the readable option to read.
On Users Submit I want to get the safe_key and the readable option both into my email.
How can I do this?
Thanks
Mike
Comment #7
david.a.king commentedHi,
I'm also struggling with this - i've used html in my "readable option" to bodge extra information for a select type - i don't want that to be displayed in the email - i'd like to use the safe_key instead. can't work out how to do it from the posts above and others.. can anyone help?
if i use
print_r($form_values)i can see the values i want[submitted_tree] => Array
(
[publications] => Array
(
[option1] =>
[option2] => option2
)
(option1 and option2 in "publications" select type)
but that's as far as i've got.
thanks
EDIT: have sorted this now with
Comment #8
quicksketchLet's keep this focused on the feature request for the 3.x version. I don't provide support for custom theming or PHP code in the issue queue.
Comment #9
jennypanighetti commentedI'm not sure if I should create a new issue or use this one since it's so closely related...
I am thinking there has to be a way to do what I'm trying to do, and that is to STORE the safe_key in the submissions table (not just in email). For example, in the list of states, I only want the state abbreviation to be stored. Same thing with some radio options - I don't want my long explanations of "I registered last year" vs "I am new this year" to be stored, I want only my safe keys "returning" and "new" to be stored.
The value of the item in the page correctly shows as the safe_key, but the label text is what is getting stored.
Bug? Feature? Can I solve it by theming?
Comment #10
quicksketchThe safe_key is ALWAYS the value stored in the database. That's why key|value pairs are now required in the 3.x version, because otherwise you might have data-integrity issues from renaming your select list labels. Perhaps you mean you'd like the keys to be used in CSV downloads? #841790: Choose to display either key or value of selection fields in downloaded CSV file
Comment #11
iwant2fly commentedI would also like to be able to display the safekey and or the value in an e-mail.
Example
1237|Purple
1234|Green
3246|Red
I want to be able to send the "safekey" to myself in an e-mail and the "value" to the customer.
I want to know the item number that was selected and I don't care about the color, and conversely the customer doesn't care about the item number.
Comment #12
merline commentedThe only thing that finally worked for me and my select fields was the following surprisingly simple code in the Additional Processing section of the webform:
In a specific example:
It doesn't seem like it should work, since I understand that the 'submitted_tree' values are emailed in the first place, but it successfully returns the safe_key as a hidden field in the email.
IMPORTANT: Pay attention to the tree hierarchy. In the above example, 'country' is nested under 'address'. Without specifying this, the field can't be located and a null will be returned!
HELPFUL: If you create more than one hidden field in this manner, you may want to tack on some sort of identifier as I've done in the example above, since the hidden field name does NOT ride along with the value. It can be a bit confusing without this.
Many thanks to the previous posters -- you gave great clues!
Comment #13
rgeddes@uoguelph.ca commentedI hoped to see this solved the D7 version. IF the key is specified then I expect this is to be the value of the field (HTML spec) with the 'human readable part' just a label. If you want them to match then make them the same but the safe_key MUST be the field value.
I am guessing that the key is not used as a string but rather an identifier in the database so I get that there is a compromise that needs to be made.
I would prefer the email tokens to be %label[key] and %value[key] for label/value respectively, and %email[key] a notational convenience for expression both with one token.
Without re-designing anything we could accomplish the result by making a %label token available to the email format.
Comment #14
HonestLai commentedSo I saw webform has moved into version 3.11. Was this feature ever added? If not, which solution above works?
Comment #15
quicksketchIf the feature were added this issue would be marked "fixed". There is not yet a working patch or permanent solution.
Comment #16
HonestLai commentedActually, it looks like from what merline posted on comment 12, I should be able to do what I need. It took a bit of researching to figure out that I needed to install Webform PHP to do the additional processing, but in theory it seems like it should work.
I'm a little unsure about the formatting however:
So I have a fieldkey for some items inside of fieldsets, which I'm guessing is what Merline is referring to in terms of country being nested under address. So far though, the php doesn't seem to be assigning new information to the fieldkey variable. I'm unsure as to how to assign the information from the safekey to the fieldkey
Comment #17
HonestLai commentedSo after hours of testing, I figured out how to assign different information to fieldkeys, but the webform php module doesn't seem to work the same way it use to in previous verions
In the above example, I figured out that I can get information from a fieldkey using ['submitted_tree']['fieldkey'], but if I want to assign a new variable to a fieldkey, I have to use ['submitted'][cid], and reference the fieldkey's component ID number... which is cumbersome considering I have over 100 components. Do you guys know a way I can reference the fieldkey with its name when I want to re-assign the information contained in it?
Comment #18
quicksketchHi @HonestLai, if you could keep this issue to the feature request and redirect your PHP questions to the Webform PHP queue I would appreciate it.
Comment #19
HonestLai commentedWill do. Should I start a new thread here for the feature request? It's pretty much the same as this thread, wanting to get the info from the safe-key in the email output.
Comment #20
quicksketchThis is the thread for the feature request. If you're trying to accomplish the same thing through Webform PHP, you should file a support request over there.
Comment #21
HonestLai commentedDone... I'll keep an eye out here for the feature request update. Can't wait until it's implemented
Comment #22
RichardLynch commentedIf you just made %post available for anonymous users, we could probably dig it out of there, yes?
POSSIBLE WORKAROUND FOR SOME CASES:
In one of our forms (built by third-parties) I think I saw somebody built a "computed" field that basically has the reverse lookup of human-readable to value=""...
I know the form works right from the GUI, and there was a computed field with names to make me believe this.
I have not, however, actually dug into it yet...
Comment #23
infringer commentedComment #1 works well.
Comment #24
nrackleff commentedsubscribing
Comment #25
tmsimont commentedhas a change been applied in 6.x-3.5?
i'm looking to just the opposite, since the safe_key is what i'm getting in the email. I actually think it made more sense to have it the other way around..
Comment #26
quicksketchNo, this still isn't fixed. There's an attempt in #1340010: Make Safe Key (in addition to Value) of Select Components accessible via tokens to fix this problem.
I couldn't find this issue before and started working in that other issue. Let's merge these conversations.
Comment #27
laughnansubscribe.
Comment #28
avpadernoI am removing issue tags used from one to four issues. I apologize for bumping the issue.