Closed (fixed)
Project:
Webform
Version:
6.x-3.19
Component:
Code
Priority:
Major
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
20 Mar 2008 at 00:23 UTC
Updated:
21 Sep 2015 at 20:47 UTC
Jump to comment: Most recent
Hi all,
I have seen this question asked a number of times, without ever receiving a definitive answer on whether or not this is even possible.
Is it possible to get at the user-submitted values from the "Confirmation message or redirect URL" box?
And if so, how?
Neither the field key nor the label seem to work -- how do we access the user-submitted values as
PHP variables? $_GET, $_POST, and $_REQUEST only seem to contain limited information.
I would like to send a confirmation email from this box, but I can't get the user's submitted email address!!!
Thanks!
Comments
Comment #1
quicksketchIt's not easily possible to get at any of the submitted information in the confirmation message. The *only* thing you have to work with is the submission ID (which is in the URL of the page if you're using just a confirmation message).
If you're using the 2.x version (which I'd recommend trying out), you can load the submitted values with the following bit of code:
Comment #2
empowerment commentedThanks! How does upgrading to 2.x beta affect existing forms?
Comment #3
quicksketchThere are changes in the theming code mostly that will affect sites that have themed the outgoing e-mails. The details of the changes are listed in CHANGELOG.txt.
If you're using webform in a "basic" capacity (not theming or using an extensive amount of form submission or validation code), then you shouldn't have to do any work when upgrading.
Comment #4
empowerment commentedNot sure if it makes sense to continue this here (please do advise on that), but I'm having trouble
upgrading to 2.x.
Whether upgrading to 5.x-2.0-beta1 or 5.x-2.x-dev, I get this error:
"The update process was aborted prematurely while running update #13 in webform.module"
And I've just tried going to 1.9 but I get the same error.
Not sure what to look for in the watchdog table, and not really up to speed on SQL, so any advice would
be much appreciated.
Comment #5
Anonymous (not verified) commentedI have added your snippet to the Confirmation message or redirect URL.
However, following error is returned:
Fatal error: Call to undefined function webform_get_submission()
I am using version 5.x-2.0-beta2.
Any ideas?
Comment #6
quicksketchOh, I forgot that webform_get_submission() is in an include file. Try this instead:
Comment #7
Anonymous (not verified) commentedThanks, I should have found that one myself!
It works now but referencing some value could be broken easily when new fields are added:
$submission['data'][4]['value'][0]
Is there any other way to retrieve the values by fieldname or something?
Thanks, Joep
Comment #8
quicksketchThe component ID (4 in your example) won't change even as new components are added or even if the component name itself is changed. I know it's a bit unfortunate that numeric indexes are used, but it's one of the reasons why Webform is no CCK. Because all data is stored in a single table, the numeric indexes are used to get speed out of an otherwise inefficient database structure.
Comment #9
Anonymous (not verified) commentedOk, that makes sense.
That will work and I will not have to worry updating fieldnames or changing the order.
Thanks for your reply.
Comment #10
quicksketchComment #11
joshuah7 commentedSince the listed code above was helpful but incomplete (at least for PHP 4), here is a full code sample:
Versions:
Webform 5.x-2.3
Drupal 5.12
PHP 4
Comment #12
najibx commentedhow about D6? just tried #11 & #6, not working.
Comment #13
myDRU commentedIn D6, #11 does work without any change, I just tried it.
Comment #14
andrewfn commentedHere is a suggestion with improved security. It prevents the submission being easily read by other users. I have only tested it on Drupal 6.
Comment #15
shanep commentedThis looks great, any way to get it to work in D5? Confirmation with no snoopers is awesome, thanks!
Comment #16
andrewfn commentedIt probably does work in D5. I just haven't tested it.
Comment #17
Lubas commentedIt doesn't work :(
I just get this:
remote_addr != ip_address()) { drupal_not_found(); module_invoke_all('exit'); exit; } $my_form_value = $submission->data[2]['value'][0]; ?>
Thank you for submitting a form
Field 2:
What do I do wrong? I just have to put it in the textarea 'confirmation message or redirection URL', isn't it?
And wich format should I use? Messaging plain text?
Or is there something i have to edit in the code?
Thanks!
Lukas
Comment #18
andrewfn commentedDo you have php enabled as the input format of the confirmation form?
Comment #19
Lubas commentedI don't really know sure, but I don't think so.
How can I enable this?
edit: I found out how to enable this, but it still doesn't work, I get the same piece of code again.
What should I do, please?
Comment #20
mpaler commentedHere's another level of security that will permit access to the confirm page for a preset period of time:
same code as #14 but with an added time check:
The "60" in the condition is seconds.
Comment #21
Anandyrh commentedHi,
Where do i need to paste this code?
Comment #22
andrewfn commentedIt goes on the confirmation page (assuming you are using a separate page for confirmation).
Comment #23
Anandyrh commentedThanks a lot man!
Comment #24
chrispooh commentedHello, is it possible to have a back link to edit the form if the user would like to change some datas?
Comment #25
attiks commentedCode is workiing, but I ran into a problem with cron, so I had to remove the line 'module_invoke_all('exit');
', I guess it has something to do with cron indexing pages for search.
Comment #27
Michsk commentedhow could i use this in a loop?
I got a x amount of questions, all awnsers got a score 0 , 1 , 2 or 3. I would need the total score for all awnser...
//EDIT: let me rephrase the question. How can i put all the points in one array so i can use array_sum().
Comment #28
devkinetic commentedhere is the view of the block I used for a site. It adds each component's question and also converts things like "not_sure" to the actual rendering of "I'm not really sure" that one would expect displayed.
Comment #29
dmidkiff commentedI have added this code to both the confirmation page and as a redirect to a custom page but I get the same error.
Fatal error: Call to undefined function webform_get_submission() in my_path/includes/common.inc(1699) : eval()'d code on line 5
Comment #30
quicksketchSupport for custom code is no longer provided in the Webform issue queue.
Comment #32
matt bfor 6.x-3.0 the following code needs to be used as the module include has been moved to a subfolder and renamed, and I've also made use of the modules functions to display the submission.
Hope this helps, but suggest you don't raise any tickets regarding your code as it appears this is not supported. You probably should consider putting this sort of code into a separate module...
Comment #34
ikeigenwijs commentedkeeping track of this idea.
Comment #35
chaosmind commentedsubscribe. the comments in this thread officially saved my butt. t'anks, everyone!
Comment #36
Sinan Erdem commentedsubscribing..
Comment #37
mbria commentedsubscribing..
Comment #38
robin van emden commentedVery useful info in this issue queue - enabled me to *quickly* create a simple conditional answer options solution in the webform-form.tpl.php, using a little jQuery magic, might be of interest to some, see:
http://druplicity.com/content/webform-conditional-answer-options
I just might create a module based on this idea, but probably will not find the time.
(ps: issue category wrong, sorry)
Comment #39
woop_light commentedI am hoping to access form values AND redirect to a Custom URL for the Confirmation Page. It appears the code is equipped to handle that based on the comment "// need to hard-code nid if this is a custom page", but I couldn't get it to work. Hopefully someone might be able to help.
A few (perhaps misguided) questions:
(1) If my Custom URL is a basic page, should the above code be pasted to the to the body of the Basic page, or still as the Confirmation Message?
(2) I see that I must no longer use "arg(1)" and instead use the Node Id. If I'm using Auto Alias, how do I figure out what the Node ID is?
(3) Let's say I learn it's 43. What exactly would I then replace "arg(1)" with? (expecting something along the lines of node/43 or just 43)
I thank everyone for their help on this.
Woop
Comment #40
umesh_chaudhari commentedi am putting following content into the confirmation message box of the webform to get the form values but i am not able to fetch any form values.what can be the possible problem.please help.
Comment #41
umesh_chaudhari commentedhi #14 worked for me after some modifications.
i had changed the following line
as follows,
and it worked for me.
Comment #42
jweedman commentedSame Here! Worked for me to change the path to just "/webform_submissions.inc"
Comment #43
sbalay commentedI tried doing with the same code. It is giving me an error
The website encountered an error while retrieving http://example.com/node/33/done?sid=127. It may be down for maintenance or configured incorrectly.
Is there something should I add to the code?
Comment #44
ressa@woop_light: You can access form values AND redirect to a Custom URL by including the nid in your custom redirect URL like this: webform-url/result?first_name=%value[first_name]&last_name=%value[last_name]&nid=%nid
sid is automatically appended, so you don't need to include that.
Use this to get the data in the webform, see what's available and print it:
This works for Drupal 7, I don't now if it will work in D6.
Comment #45
ibexy commentedThis give the error:
Notice: Undefined index: nid in eval() (line 2 of /mywebsite/modules/php/php.module(80) : eval()'d code).Notice: Trying to get property of non-object in eval() (line 11 of /mywebsite/modules/php/php.module(80) : eval()'d code).am using Drupal 7
Comment #46
ressaYou can see under "Token values" if %nid is available, I think it should be, but perhaps it's another issue? I ended up using this shorter version: webform-url-result/%nid/%sid and getting the values using arg(1) and arg(2).
Comment #47
doublejosh commentedIt should be noted that the $data[INDEX] is from the component created index not it's sort order... which is good.
My code ended up looking like...
My use case is processing values into a composite "score" in place of that output.
Comment #48
Manick commentedCan Anyone help me in this? I need to create users as and when an anonymous user fills webforms. I did use some forum material to create new users - using User_save function. But what happened was when i tried to fill the form with same user name got Exception error. Ofcourse, as 2 users should not have same username.
In addition to that, if the user is already logged in and if he tries to submit, that will be an error as the account already exits. Is there any way that i can go about in avoiding errors. I tried using webform rules module. But there wasn't much of explanation/ examples from which one can learn
Comment #49
devkinetic commented@Manick Please keep this thread focused on the original issue.
Your question is better suited for submission to the drupal stack exchange, as it involves writing custom code, and is not an issue with the intended functionality of the webform module. One thing right off the bat is you need to add checks to see if the username exists, if the user is logged in already, etc.
Comment #50
cats commented$_GET['sid'] works for a separate confirmation page, but how would I access the SID if I'm redirecting back to the original form?
Comment #51
quicksketchYou can use the %sid token in your redirect URL to include it in the query string of your redirect URLs in the 3.x version. In 4.x you can use [submission:sid].
Comment #53
matness123 commentedHi everyone, I found this post helpfull.
With Drupal 7 I am unable to get data in the submission array with the provided code :
$submission->data[1]['value'][0], it returns nothing
Simply remove the ['value'] and it's now working fine !
Using webforms 4.x and Drupal 7.x
Thanks !
Comment #54
d8v15 commentedusing drupal7 webform 4 and this code doesnt work.
I show the confirmation message in a jquery pop message (reload current page). My goal is simply to get a value from the form and show in the "confirmation message" box.
after including the scripts in "confirmation message" as above, calling arg(1) returns "ajax". As well, there is no value sid in the get string. With this i cannot retrieve form values (webform_get_submission returns nothing).
Please advise.