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!

1 Answer 1

25

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
2
  • 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
    Commented Aug 1, 2013 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 Commented Aug 2, 2013 at 1:16

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