*title*, I would like to take in the form information, process it, then store it some info in a hidden field within the same form. Right now it is being processed correctly but not stored (field key is named serial_key). This is what I tried:
$form_values['submitted_tree']['serial_key'] = $output[10];
Also I would like to create a page where a user can see information from multiple times submitting this form (system_id and serial_key) and have the option to delete them individually (checkboxes maybe). Using only webform, can I give them permission to see/delete their results but not edit them?
Comments
Comment #1
bmeier commentedI was mistaken, when I did this (below) I got the correct information, but when I try to look at the results of the form submissions the serial_key field is empty.
It seems I don't really understand the concept of a hidden field. Is there a way to associate an extra piece of data with a given form?
Comment #2
quicksketchLooks like you have two separate requests. To allow the user to see and delete the submission but not edit it... that's an existing feature request. #269709: Add separate "delete" permissions, add "any" to distiguish from "own" permissions
You may be having trouble with hidden fields if you're setting the default value via a %get variable. It's an existing bug here: #223388: %get[], tokens do not work in disabled or hidden fields
Comment #3
bmeier commentedIssue 1:
The newest Webform module allows 'delete webform' permissions to be set so I used that.
Issue 2:
I realized that I should be using form_set_value but get an error, my code is:
and the error:
I have verified the $data variable is correct by echoing it but when I view the submissions there is nothing in the serial_key field. I also tried setting the field's default value to '0', just to see if it would be overwritten but it wasn't. Any help would be greatly appreciated I have spent a lot of time testing and searching for answers.
Comment #4
quicksketchWebform creates 2 arrays: $form_values['submitted'] and $form_values['submitted_tree']. The "submitted_tree" is useful because it contains a hierarchical representation of the form ordered by the field keys. However, Webform uses the "submitted" key to actually save data. The "submitted" array is not hierarchical, instead, all the values are keyed by the unique internal component ID. So you'll need to do something like:
Comment #5
bmeier commentedThe field is the 6th component on the list so I tried ['submitted'][5] which did not work. I also used phpmyadmin and found that the empty field in the webform_submitted_data table was at cid = 7 so I tried that but neither worked. As a test I tried a few other numbers but none of my results changed. I've tried in the "additional validation" and "additional processing" boxes as well. This guess and check work is a bit frustrating, is there a guide for novice users somewhere? Thanks for the suggestions though quicksketch.
Comment #6
frasketi commentedI'm struggling with this too. I'm trying to populate a request_id field with a value. I can get the value in the emails, but nothing is stored in the database. Any help would be great. Thanks
Comment #7
csherg commentedI also vitally need the ability to set the value of a hidden field, programmatically, via the Additional Validation hook. I can use form_set_value and it appears to work fine - pumping the $form_state variable into a drupal_set_message immediately after calling form_set_value shows the values updated correctly - but those changed values don't show up in the submit hook.
Could it possibly be that $form_state isn't passed by reference to the Additional Validation hook?
I'm perfectly willing to patch this myself, just need to know where to start. Any help would be appreciated.
Comment #8
csherg commentedWell... that was easy. As I suspected, the validation hook wasn't passing $form or $form_state by reference. I changed line 1588 of webform.module from:
function webform_client_form_validate($form, $form_state) {
To:
function webform_client_form_validate(&$form, &$form_state) {
And it works. Patch attached.
Comment #9
quicksketchThanks, I converted the $form_state to be passed by reference in the in _validate handler (though I left $form as not-by-reference).
Comment #11
quicksketchI had to roll back the change in #9, since it effectively broke all submissions. :P
It can't be passed by reference, since the $form_state['values']['submitted'] value must not be flattened before the submit handler. So the the $form_state value will continue to not be passed by reference. Please open a new issue with a patch if you've found a suitable work around.
Comment #12
elpino commentedquicksketch,
is there then no known solution yet or is your last comment specific to using a $form_state solution (because $form_state can't be passed by reference)?
or is it then not possible to change or add values to fields through the $form_values['submitted'] array during validation??
or even worse, no value alteration whatsoever during validation?
I changed status back to active since patch did not work and no solution has been offered, sorry in advance if I'm mistaken.
Comment #13
Whiskey commentedI'm very much interested in a fix or workaround as well.
Comment #14
quicksketchThat's right, currently there's no way to change $form_state values in the validation handler.
Comment #15
dev16 commentedThanks for this thread.
It seems to me that I can use only drupal_set_message or drupal_set_error to interract with user when I use webform module.
Anybody found solution hot to change a field values in Additional Validation or Processing handlers and send changed values back to end user?
Or do I have to create custom module for it?
Comment #16
guislutavo commentedI use
$form_values['submitted_tree']['name_of_the_component']and$form_values['submitted']['name_of_the_component']when i want to see the values of the submitted webform fields, send emails and print screens of confirmation (pretty similar to email confirmations: http://drupal.org/node/399064). I put these in the Additional Processing box.
but I only found that
$form_state[values][submitted][sid]works for storing the data in the database... (http://drupal.org/node/396168#comment-1392978) I think this could be a bug...Comment #17
obsidiandesign commentedSubscribing
Comment #18
chriscalip commentedsubscribe
Comment #19
shaunlaws commentedAfter hours of struggling with this I was finally able to set the value of a hidden field called 'contact_email' using this set up:
In mymodule.module:
The important thing here is the ['submitted'] key. Seems like webforms generates the form fields with the 'submitted' array.
I put that same form_set_value code .i.e.
into the Additional Validation text area of the webform edit and it failed to have any effect, presumably because of the 'pass by reference' issue mentioned earlier in this thread.
Hope this helps.
Comment #20
quicksketchThanks for the update ShaunLaws. As noted in the submission guidelines, support for writing custom code is no longer provided in the Webform issue queue, so I'm closing this issue.
Comment #21
Todd Young commentedFor those still pulling your hair out with this, I hammered a good while on it and the following works in the 'additional processing' section of a webform - even for hidden fields:
If you turn on 'Full Debug' mode in Webform settings you will get a dump of what each of your submitted id #'s are.
Comment #22
halefxThank you, Todd! I used this to save a session variable with the form. Only the 'submitted' value appears to be necessary for saving the data to the database, but I went ahead and added both lines in case it makes a difference elsewhere.
Comment #23
scott_earnest commentedThis note will pertain to version 3. In this version, the additional processing field has gone away for security reasons. I added a custom submit handler in a hook_form_alter that did some additional processing and that worked just fine. However, when I tried to populate a hidden field in the webform the data was not showing up in the results.
After looking into the webform_php.module file, I realized that any additional submits need to occur between the two webform submit handlers.
So, these lines are key when adding submit handlers in webform v3 in a hook_form_alter:
Comment #24
gausarts commentedSubscribing. Thanks
Comment #25
taggartj commentedFor the ones of us who still have people on D6:
here is a code that may help... new module name = "webform_val"
there is a lot of stuff out there that can help all though for cck field
Create a link to node/X (in my case 10) with a get var
Example: node/10?n=100 , node 100 has a cck field " field_email_send_to"