5

I have a webform (www.mysite.com/myform) ad I want to be able to pass a URL string to a text field in the webform when a user visits the page and submits it. For instance, the URL provided to "customer A" might be www.mysite.com/myform?customer_name=customera and the URL provided to "customer B" might be www.mysite.com/myform?customer_name=customerb. I would like for the value of the text field "Customer Name" to be auto-populated with "customera" or "customerb" depending on the URL used to access the webform page.

Is this possible? If so, how can I accomplish this?

Going a bit deeper... if this is possible, is it also possible to pass two strings via the URL so that two separate fields are auto-populated? For instance, www.mysite.com/myform?customername=customera?customer_type=lead would auto-populate "Customer Name" with "customera" and would auto-populate "Customer Type" with "lead".

Thanks!

26

You can set a default value for each field on your webform. The default value you would use would be

For Webform v3 and under:

%get[customer_name]

For Webform v4+:

[current-page:query:customer_name]

To get a first and last name you could do something like:

URL:

http://mysite.com/myform?first_name=John&last_name=Doe

First Name Default Value:

%get[first_name]                 //webform <= v3
[current-page:query:first_name]  //webform >= v4

Last Name Default Value:

%get[last_name]                 //webform <= v3
[current-page:query:last_name]  //webform >= v4
  • Patrick, thanks for your answer. I followed your instructions, but now the two form fields on the live site simply show the %get[key] text in the field instead of the values from the URL string. Any idea why that would happen? It's almost like it is not respective the token. I should also say that I am using Webform 7.x-4.0-alpha6, in case that has any bearing on anything. – hockey2112 Aug 1 '13 at 20:19
  • @hockey2112 Webform v4 uses a different approach, you would use [current-page:query:first_name] and [current-page:query:last_name] instead of the %get[] defaults – Patrick Ryan Aug 2 '13 at 1:16

protected by Community Mar 15 '15 at 22:17

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.