1

On a Drupal 8 site, I have a content type called TeamMember which has an email field. From the view where I show all the TeamMembers, I'd like to link to a form where the user can email that person directly. Is there a way to customize the recipient of the email from a contact form?

2

What we do in a few places is to have a hidden reference field to the team node in your contact message entity.

Then you pre-fill that when displaying the contact form and later on in hook_mail_alter(), use that information to change the recipient.

Requires a bit of custom code but then you don't have to create a lot of contact forms.

  • In my opinion this is also the only solution for creating forms with different recipients depending on the selected message subject. – 0711master Feb 23 '17 at 14:51
1

Contact forms in D8 don't have customizable recipients out of the box so you're going to need some sort of workaround.

A couple of paths that you could take:

  1. Treat your TeamMember not as Node entities, but as User entities. Use their profile page (/user/X) as the content page and use the personal contact form (/user/X/contact) as the per-TeamMember contact form.
  2. Keep the TeamMember, but create a unique contact form for each TeamMember. On the TeamMember node type, create a Link field that links to each unique contact form you've built.

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.