You are here: Home / Documentation / How To's / Creating a Custom form emailer With PFG

Creating a Custom form emailer With PFG

by herronj — published Aug 16, 2016 10:49 AM, last modified Aug 16, 2016 10:49 AM
Instructions for making a form mailer with more power

A common thing to do with form submissions to want to display different content based on answers to certain form field data. While PloneFormGen offers a mail adapter, customizing the output is limited to basic tal blocks so more advanced python is unavailable. The answer to this is to use an override in the "Custom Success Action" this will allow us to use a python script to build and send our email.


Pre-reqs for this tutorial are:

  • ZMI access
  • Working knowledge of the python language

 

 

In the ZMI navigate to your PFG form folder and create a new Script (python). name it something short but memorable, for this example i'll be calling mine customMailer.

 
First order of business, let's get the basics of our script setup. 
 
I perfer to work outside of the ZMI to produce code and then upload my finished file into the ZMI.
 
In your favorite text editor, make a new file called customMailer.py and add the following code:
 
request = container.REQUEST
form = request.form

try:
  from Products.CMFCore.utils import getToolByName 
  mailhost= getToolByName(context, 'MailHost')
except:
  raise AttributeError, "cant find a Mail Host object"

mMsg = mMsgTop + degreeInfo + certinfo + mMsgAchieve
mFrom = 'gradschool@uwosh.edu'
mSubj = 'Request for Information'

mailhost.send(mMsg, mTo, mFrom, mSubj)

container.REQUEST.RESPONSE.redirect(context.portal_url()+'/gradstudies/thank-you')

 
traverse_to:string:custom-email
 
Navigation