4

I am currently working on a Drupal 7 site in which the contact form must email a particular representative based on whether the user belongs to a certain company or is in a certain location. The first check would be based on the company of the user so that if that company has a rep then they would get the email. If not then a country rep would be sent the email. Currently I am using webforms for the contact form.

I was thinking that if it was possible to add rules or conditions to the recipient emails of the webform based on fields in the form, that would be a good place to start. However after looking around and talking to a few people I'm not sure if this option exists at the moment. I would also be open to any suggestions on a different way to achieve this. Thanks to anyone who may have any advice.

2

What you want to do, certainly cannot be done with just webform.

But you may be able to pull it off when combining Webform with Rules and Webform Rules.

You can add a rule to fire at the event of a webform submission. As condition you will add the nid of the webform so you are sure this specific webform only triggers this workflow. You can also add you own php code as a condition (or no code at all if you are just going to do simple comparisons.). The good thing in this process is that all the submitted data are available through Rules so you can just grab them in your code/conditions to see if the data meet the criteria. If all the conditions are met then you will add an action to send an e-mail to either a specific user or all users of a role.

  • This answer is partially misleading, ie the phrase "The good thing in this process is that all the submitted data are available through Rules so you can just grab them in your code/conditions to see if the data meet the criteria.". That's not true. To understand what I mean, refer to this answer (disclosure: it's mine ...). – Pierre.Vriens Nov 21 '17 at 9:31
1

I'd go for a custom module.

  1. Build the form using FAPI.
  2. In the submit handler get the properties of the user.
  3. User drupal_mail() to send your mail.
0

Webform already supports basic conditional e-mailing as per the Conditional recipients documentation page.

If that's insufficient for your purposes, other advanced options are reviewed on the Webform Bonus Pack: email routing in webforms blog post.

Do as little custom work as possible (only if you need it) so that'll you'll have an easier time upgrading and maintaining your code.

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.