1

I have a Drupal 7 webform with a dropdown list of Products - Product A - Product B - Product C - etc...

I want to place a button link on another page "How to Buy Product A" that will bring up the webform with Product A selected in the dropdown.

The Field Key in the Webform for the dropdown is: railing_system_model

Do I just add something to the link URL??

I have no idea where to begin, is there a module that will do this?

Regards,

John

1

hook_form_alter() or hook_form_form_id_alter() is what you're looking for here.

First your link how ever it's constructed should have a query parameter kind of like "/webformurl?product=a". This would be a link back to your webform.

In one of the hook form alters, you'd check for the value in the url if it doesn't exist do nothing. If it does change the default value for the form field.

If you're not sure how to alter the field on your form maybe check out this link for additional details - Programmatically modifying a webform with hook_form_alter()

5
  • Thanks Chad but I have no clue how to implement hook_form_alter() and the link you provided was way over my head.
    – John
    Oct 6 '16 at 18:14
  • @john have you ever made a custom drupal module?
    – Chad Payne
    Oct 6 '16 at 21:10
  • nope, can't even understand the tutorials on how to do so, way out of my league
    – John
    Oct 7 '16 at 13:25
  • What type of field is it? Oct 7 '16 at 13:49
  • WebForm Select Options Field
    – John
    Oct 7 '16 at 20:55
0

The Prepopulate module will let you pre-set most form values by adding a parameter to the URL corresponding with the field name. You'd use something like this (inspect your generated form for the proper variable name to use, and watch you are using the proper underlines/dashes):

http://www.example.com/node/add/blog?edit[railing-system-model]=your_key

2
  • why "node/add"? I'm just pre-selectiong a field in a webform, node adding a node
    – John
    Oct 24 '16 at 19:46
  • node/add was just an example URL. It would work on any path showing a Drupal form generated by the Form API. The key part is the ?edit[YOUR_FIELD_NAME_HERE]=YOUR_VALUE part.
    – diamondsea
    Mar 9 '17 at 22:12

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.