[Zope] Still Chipping Away At Formulator/ZPT Interface
Clemens Robbenhaar
zope@zope.org
Tue, 5 Nov 2002 22:59:39 +0100
Hi beno,
[snip dtml code]
> >
> >In ZPT, it would be
> >
> > <tr tal:repeat="field here/form/get_fields">
> > <td tal:content="python: field.get_value('title')" />
> > <td tal:content="structure field/render" />
> > </tr>
> >
> >As you see, it's easier than in DTML.
>
> Actually, I need to do this in Python, since I'm calling the MailHost. I
> figured out how to do that, but discovered that's not what I wanted <:-)
> What I *really* need is to be able to call the values the visitor enters
> into the fields in the form. For example, on the page to which POST sends I
> would write something like this in DTML:
> <dtml-var the_variable_the_visitor_filled_in_goes_here>
> and it would render the information accordingly. I need to do that in
> *Python*, not ZPT. How?
Actually You want to verify the submitted form data first, then read
out the data to do something, I guess.
This looks like:
from Products.Formulator.Errors import ValidationError, FormValidationError
try:
result = context.email_us_formulator.validate_all(context.REQUEST)
except FormValidationError, e:
# render error message; e.g. see mailing thread at:
# http://sourceforge.net/mailarchive/forum.php?thread_id=1272274&forum_id=1702
# if verification succeeded, You now have all filled in values
# in the dictionary "result"
try:
mailhost=getattr(context, context.superValues('Mail Host')[0].id)
except:
raise AttributeError, "cant find a Mail Host object"
mTo = 'beno@thewebsons.com'
mFrom = result['YourEmail'] # assuming 'YourEmail' is the id of the corresponding Formulator Field
mSubj = 'subject'
# assume Field ids beeing 'YourName', 'YourPhone', etc ...
message = "Hi, Mike! You've just been sent an email from your Web site!\n\n"
message += "Sender's name: " + result['YourName'] + "\n"
message += "Sender's phone: " + result['YourPhone'] + "\n"
message += "Sender's email: " + result['YourEmail'] + "\n\n"
message += "Sender's comments: " + result['YourMessage'] + "\n"
mMsg = message
mailhost.send(mMsg, mto=mTo, mfrom=mFrom, subject=mSubj)
# feedback message: needs a ZPT with id "mail_send"
# read name of submitter from "options/name" in this ZPT
return context.mail_send(name=result['YourName'])
Note 1: I did not rewrite the String concatenation as proposed in a
previous posting in this thread. This does not mean I have any
objections to it; I have just been to lazy to retype the example.
Note 2: I admit I did not test the code this time, again. Sorry for any
typos ...
Cheers,
Clemens