Personal tools
You are here: Home Products PloneFormGen Documentation How-Tos Use a Selection Field to Pick Mail Destination

Use a Selection Field to Pick Mail Destination

This How-to applies to: Any version.

You may allow form users to use a selection field to choose a destination address for their form input.

I'm trying to use a PloneFormGen form as a support center for my project and I would like to have the mail sent to different email addresses based on a choice from a selection field.

How can I do it?

First, create a selection field in your form

In the Options field, specify your set of possible destination addresses in a "value|label" format where the e-mail address is the value and its readable name the label. E.G.,

softwarehelp@example.org|Software Support Desk
hardwarehelp@example.org|Hardware Support Desk

Then, pick the address (the actual e-mail address value,  not the label) you wish selected by default. Put it in the Default field. Make sure the Required checkbox is selected.

Save the form field.

Configuring the mailer

Now, edit the mail adapter for your form. (Navigate to the form folder, click on contents, find your mail adapter and follow the link; select the edit tab.)

Choose the [addressing] sub-form and find the Extract Recipient From field. You should see a None choice and a list of all of the selection fields in your form. Select the field you just created and save your changes.

adding parameter in URL to select default email address

Posted by Michael Schreiber at Jan 17, 2007 08:51 PM
Is there a way to pass a GET to the form through the URL to have the dropdown of the department/email default to the selected GET parameter?

i.e. contact?dept=hardware
would select the hardware department. This would be useful when putting mail links on other sites, where you may want to send them specifically to the hardware department in one case, and the software department in another.

Sure

Posted by Steve McMahon at Jan 17, 2007 09:17 PM
Zope marshals both GET and POST data into the request.form dictionary, which is what's being used to set form defaults. So, yes.

But, the query string argument will need to be a value from your option list. So, you would have use:

contact?dept=newguy%40hardware.domain.com

(The @ is URL escaped.)

The problem with this is that you may not wish to be revealing addresses in URLs.

The alternative is to have department be a hidden field (so that it gets remembered) and use a script to read it and set your recipient field to something real as a "Recipient Expression" override in the mailer.

Setting an email address dynamically through SQL

Posted by Michael Schreiber at May 30, 2007 01:28 PM
For those of you who want to populate a field through dynamic methods (specifically SQL), you can do it via the following method:

1) Add a selection widget.
a) Click on the "overrides" link to alter the default expression, and options vocabulary
b) Add your two (different scripts) for querying your SQL for each:
here/query1 ; "default expression" requires one parameter, and can be a simple query requesting the email address [which you want to be default]
here/query2 ; "options vocabulary" requires two parameters, the value and the text; if you wish the values to be the same then do a "select email as email_address,email from tablename" so both values are returned (you can't select the same thing twice)

2) Change the mailer addressing option to use your selection widget as the mail to.

HTH, for those of us doing crazy/wacky things with the PloneFormGen!

Sending message to user

Posted by Web Ed at Jun 23, 2008 11:20 AM
Is it possible to let users decide whether to receive a copy of the email as well? I thought it might be possible with a boolean field, but I can't figure out how to append the email address the user inputs to the list of recipients in the mailer adaptor...

Any advice appreciated

Thanks