Score:1

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

ph flag

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.

Score:1
de flag

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 
  }
Score:-1
cn flag

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

sonfd avatar
in flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.