Forum
Mail a form response to different addresses based on field
Is it possible (out of the box) with forms to have a form response mailed to a different email address depending on the value selected in a drop down field in the form? If not, any pointers as to how to go about implementing this?
Alan,
If the form were public facing it could be exploited for spam if you use a select box for this task. All a spammer would need to do is substitute the option with new values and it becomes a spamming machine.
You would need to create different forms for each of the addresses then setup in the forms app where to send each form. Then you will use perch_form() to display the forms based on page content templates.
Not sure if this solution would help ... We have a form on a site where a range of subjects are in a dropdown menu. All the form output is emailed to the same address and a rule there redistributes the messages to the right people.
@Robert: Thanks for your response. Just to clarify, I don't intend for the select box to surface the email addresses client-side. For example:
<select id="department"> <option value="marketing">Marketing</option> <option value="finance">Finance</option> ...
and then in the form-handling PHP, I would have an associative array mapping the option values to email addresses.
What I'm wondering is if there is a hook point somewhere in the Perch forms app (or somewhere else?) where I can just override this hardcoded recipient address at submit time?
I've had a look through the Forms App source and can see where the "emailAddress" key is set and used but I don't know how or if it's possible to hook into this and override.
Thanks again.
@Graham: Thanks for your response. Yes - this is an option I'd considered, but I wanted to be sure I wasn't missing any baked in functionality in Perch.
Alan, you could write a simple app then add this app to the 'app' attribute of the perch_form.
That is the best "hook" I can think of. I would have to look back through the forms app to refresh my memory on the actual flow of submitted forms.>Alan Pyne said: >
Alan, you could write a simple app then add this app to the 'app' attribute of the perch_form.
That is the best "hook" I can think of. I would have to look back through the forms app to refresh my memory on the actual flow of submitted forms.
like...
simplest way to do this is to use a field variable in the email address field
so if your form has a select box or radio box with name "reason" for example, then in the Email Addresses box simply put {reason}@mydomain.com
As long as all the values match up to your email addresses it should all work simples