from Products.Formulator.Errors import ValidationError, FormValidationError
# Change the next line to the name of your form, i.e. "context.name_of_my_form"
form = context.email_us_formulator
# Here I initialize a couple of variables
i = 0
myField = []
for field in form.get_fields():
myField.append(field.get_value('title'))
i = i + 1
# Here we'll catch errors. BE SURE TO CHANGE THE NAME OF YOUR FORM!
try:
result = context.email_us_formulator.validate_all(context.REQUEST)
except FormValidationError, errlist:
print "<font style='font: 17px'>I'm sorry. Some of the information you entered "
print "was either incorrect or incomplete. Please use the "back" "
print "button and fill it in correctly. Thank you!<br><br>"
for error in errlist.errors:
print '<b>' + error.field.get_value('title') + ': '+ error.error_text
print '</b><br></font>'
return printed
# If we didn't get an error, then let's print the page thanking the visitor for
# filling out the form.
if result:
print "<font style='font: 17px'>"
print "<br><br><br><br><br><br>\n"
print "<center>\n"
# 'YourName' is a variable I create in my Formulator forms. Substitute whatever you use.
print "Thank you, " + result['YourName'] + "! We'll be sure to follow up "
print "with you shortly!<br><br>\n"
print "Sincerely,<br>\n"
print "<b>Homer Simpson, owner</b>\n"
print "</center></font>"
# Now, let's see if we can connect to the MailHost.
try:
mailhost=getattr(context, context.superValues('Mail Host')[0].id)
except:
raise AttributeError, "Can't find a Mail Host object."
# Here we fill in the variables for the email we'll send. Change the
# values to your needs.
mTo = 'Batman@GothamCity.com'
# Once again, I use the variables (such as YourEmail) that I create in my
# Formulator form. Substitute accordingly.
mFrom = result['YourEmail']
mSubj = 'Feedback From Your Web Site!'
message = []
message.append("Hi, Snoopy! You've just been sent an email from your ")
message.append("Web site!\n")
message.append("Sender's name: %s" % result['YourName'])
message.append("Sender's phone: %s" % result['YourPhone'])
message.append("Sender's email: %s" % result['YourEmail'])
message.append("Sender's comments: %s" % result['YourComments'])
mMsg = '\n'.join(message)
mailhost.send(mMsg, mto=mTo, mfrom=mFrom, subject=mSubj)
return printed
|