4

I have created the query string for the particular fields.

My URL : www.examples.com/path?title=something

How could I pass the "title" query string value to webform field's default values.

3 Answers 3

11

This can be done in the webform backend settings: Edit your webform and go to Settings >> Form; then go down to Form Behaviours and select Allow all elements to be populated using query string parameters.

If you go back to the webform element, select the particular field, and enter [current-page:query:full_name] as default value (where full_name is the field name), if the query string contains full_name=John+Smith, the full_name field will be populated with Josh Smith.

2
  • Is marking "Allow all elements to be populated using query string parameters" really necessary? If I set that, any form field can be set to an arbitrary value passing the form key as the query string name
    – Pere
    Commented Sep 8, 2020 at 7:02
  • Confirmed: when using the Token module, "Allow all elements to be populated using query string parameters" setting per form or field is not necessary at all
    – Pere
    Commented Sep 8, 2020 at 12:25
1

To do this you need to go in your form and edit the field. In the edition modal window, go into the third tab "Advanced", where you can define the default value and add [current-page:query:your_parameter] in the field, which in your case is [current-page:query:title]. You can find all the tokens available by clicking the "Browse available tokens" at the bottom of the modal window. (don't forget to save)

0
0

As of today, the default value needs to be explicitly set for some types of fields, for instance, a text field. I have found that a selection field with entity references for values does not need to have the default value set, but that a simple text field does.

So, edit the field you wish to populate from the query string, note the Key value beneath the Title field, scroll down to the Form Display section and check Prepopulate. In the Advanced tab, set the default value to [current-page:query:].

Be sure to save and maybe clear caches.

Now, loading the form with a query string like:

?service=10&pi_first_name=Chuck

Will cause the service selector (radio buttons) to be set to the entry whose node id is 10, and the PI First Name field to be filled with "Chuck."

Not sure why some fields require a default value to be set, and others do not, that would be a question for jrockowitz.