Extending PloneFormMailer to Capture data into a MySQL database.
This script enables to store form data before emailing it in a MySQL database.
For ex:
1) The form whose data to be captured is at {site-root}/forms/join-us/ploneformmailerJoinus/.
2) The data to be captured will be:
>field_fullname
>field_email
>field_Country
>field_message
3 Create a ZSQLMethod named insertjoinrecords which will be connecting to you MySQL database with the following details.
Arguments : name email message language
SQL : insert into newsletter (name,email , message, language ) values ( '<dtml-var name>','<dtml-var email>','<dtml-var message>','<dtml-var language>');
4 Customise the PloneFormMailAdder (controller script).
> Navigate to '{siteroot}/portal_skins/PloneFormMailer/formmailer_send/manage'.
> and 'customize'.
> Then rename the newly customized controller script to joinusstoreandemail(You can name anything).
> Under the 'Proxy' tab, set the proxy role to Manager.
> Edit the script so that it looks something like the one below:
----------------------------------------------------------------------------------------------------
# Controller Python Script "joinusstoreandemail"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind state=state
##bind subpath=traverse_subpath
##parameters=
##title=
#some useful utilities
from Products.CMFCore.utils import getToolByName
urltool = getToolByName(context, "portal_url")
catalogtool = getToolByName(context, "portal_catalog")
portal = urltool.getPortalObject()
request=context.REQUEST
#generate a unique entry name
date=str(context.ZopeTime().strftime('%Y-%m-%d-%H:%M:%S'))
l=[]
for key in ("field_fullname",
"field_email",
"field_Country",
"field_message"):
value = request[key]
l.append(value)
for result in context.insertjoinrecords(date=date, fullname=l[0], email=l[1], country=l[2], message=l[3]) :
print 'success'
context.send_form()
return state #this is critical!!! redirection and send response will not work
# without this
----------------------------------------------------------------------------------------------------
5 Set PloneFormMailer to use your custom controller script
> Go to '{siteroot}/forms/join-us/ploneformmailerJoinus/' and 'edit' the formmailer.
> Under the 'Controller' section set an alternate controller python script (cpy) as 'string:joinusstoreandemail'
