4

When I click a webform link, I want one of the checkbox checked. I've set already set up the default value for that checkbox as %get[foo] in Webform.

I tried:

a href="node/34?foo=checked"

a href="node/34?foo=selected"

a href="node/34?foo=1"

a href="node/34?foo[]=1"

Am I missing something?

2

Webform provides this functionality by itself.

  1. Define in your checkbox field a default value:

    %get[customkey]

custom key capture

  1. The url will be:

    http://example.com/node/1?customkey=one,two

webform url capture

1

Use [current-page:query:foo] in Default Value field and set query string to node/1?foo=1,2 and it will work.

Installing Tokens module will show you some values you can use in your default value field.

0

Keep in mind that, at the moment of writing, there's an issue with tokens and the Options Element module in Webform.

-1

This feature is not directly available on Webform module. You've to implement some code to prefill the form fields.

A simple method is to write some JS which reads the URL parameters and set the values to the corresponding fields.

There are many ways to implement this code. This is an example of JavaScript code:

var current_url = window.location.href;
if (current_url.indexOf('foo=') > 0){
  $('#field-id').val(current_url.substr(current_url.indexOf('foo=') + 4));
}

At first the script get the current url and if the "foo" parameter is found, then the value will be loaded and used to set the #field-id value. #field-id is the id of the input field on the webform. 4 is the length of "foo=".

If you have many parameters you can use

current_url.split("&")

method which returns an array with all the parameters.

  • I know my method works because I grabbed the value of foo for a text-field. It just I don't know how to pass a value for checkbox. TQ for taking time for typing out the JS code. It just I'm reluctant to enable phpcode in my webform for fear of being compromised. – Jessica K Jan 5 '14 at 15:45
-1

You can use the Prepopulate module which autofills your fields. Here is a quote about it (from the module's project page):

... allows fields in most forms to be pre-populated from the $_REQUEST variable.

For example, the following URL,

http://www.example.com/node/add/blog?edit[title]=this is the title

will automatically fill the Title field on a new blog post with the words "this is the title". Any field can be prepopulated this way, including taxonomy and CCK fields. You can prepopulate more than one field at a time as well. Prepopulate is excellent for creating bookmarklets.

  • This is not what I want. I'm on D7. – Jessica K Jan 7 '14 at 10:25
  • The module also have d7 version. It's currently in dev version but you can use it I think. – gfarishyan Jan 7 '14 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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