0

I created 2 types of contact form. I disabled Subject in Manage form. I want the fake Subject field not to be displayed in the contact form, and I want it to be filled in automatically.

How do I automatically fill the subject in the contact forms?

There is nothing in the contact form settings to enter static text in the subject field.

2 Answers 2

1

If working with Drupal contact forms (and not Webform), it would be something like:

  // Replace HOOK with 'yourThemeName' or 'yourModuleName' depending on where you put this code
  function HOOK_form_alter(&$form, FormStateInterface $form_state, $form_id) { 
    if($form_id == "your_contact_form_id") {
      $form["subject"]["widget"][0]["value"]["#default_value"] = "Hi, how are you?";
      $form["subject"]["widget"][0]["value"]["#type"] = "hidden"; // Hide field from display 
  }
-1

Set default value for the form either in settings or you can do it via hook_form_alter(). Then set the filed as disabled.

1
  • I didn't down vote your answer, but this would be a good answer if you explained further. For example, explain how to "Set default value for the form in settings" and show some hook_form_alter() code.
    – sonfd
    Commented Jul 4, 2021 at 20:18

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.