4

I have a standard contact page created using webform, which has a set of radio buttons.

Is it possible to change the pre-selected radio option based on the referring page?

4 Answers 4

0

I would add ?selectValue=yourvalue to the links pointing to your webform.

Then, create a template node--webform.tpl.php, check if i'm in the correct webform with the $node object and if $_GET['selectValue'] is set. Then use jQuery to select my radio button.

It might not by the perfect solution, but it's clearly a way out!

1
  • This solution needs jQuery enabled, there is better approaches on this topic like tokens or just do a custom form_alter
    – jorgetutor
    Commented Aug 5, 2014 at 17:09
1

With Webform you can pre-populate form default values via the url with tokens:

Setting Default Values from the URL (7.x-3 and earlier)

The %get[key] supported by Webform allows form values to be populated from the URL.

Setting Default Values from the URL (7.x-4)

To set the default values of a component to use either:

Query Format: For urls formatted like http://example.com/node/120?key=bar use [current-page:query:key] to return key value.,

Args Format: For urls formatted like http://example.com/node/120/key use [current-page:url:args:2] to return key.

Taken verbatim from webform docs

1

In Drupal 8 using Webforms module you can do the following:

admin/structure/webform/manage/donation/source

Add: '#default_value': 'Yes'

To the radio button defined in the YML.

0

When you are adding new field in webform, select "Select option" in the type of field. After that you will get a field configuration page. In field configuration page you will see 3rd option as default value. You can put default value for that field.

1
  • When I set the default value there, it is the same no matter what page you come from. I want the default option to change. Eg. if clicking the webform link from the sales page, then the sales enquiry radio option is pre-selected by default; if clicking webform from about us page, then general enquiry option is pre-selected.
    – Rooneyl
    Commented Jan 12, 2012 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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