0

I have a contact form build from the drupal core contact forms.

I am trying to prefill some fields from URL GET parameters like this. /?foo=bar But it seems that "default value" doesnt support tokens.

I want to use something like this: [current-page:url:args:value:foo] in the default field of my form field.

But this gets just rendered as plain text. Any help is appreciated.

EDIT: Working solution with form_alter:

function MY_MODULE_form_alter(&$form, &$form_state) {
  $args = \Drupal::request()->query->all();
  $form['field_test']['widget'][0]['value']['#default_value'] = $args['foo'];
}

Maybe there is a solution with tokens relating to the topic?

1
  • Can you show more code ?
    – rémy
    Jun 10, 2016 at 8:47

1 Answer 1

1

Usually this is done in hook_form_contact_site_form_alter, like this:

function YOUR_MODULE_form_contact_site_form_alter(&$form, &$form_state) {
      $args = \Drupal::request()->query->all();
      $form['subject']['#default_value'] = $args['foo'];
}
1
  • Thanks for your solution. I thought I could make some approach with tokens. But your solution worked for me with some modifications. I will update my question
    – Nicensin
    Jun 10, 2016 at 9:13

Your Answer

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

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