[Zope] Still Chipping Away At Formulator/ZPT Interface

beno zope@thewebsons.com
Tue, 05 Nov 2002 19:46:26 -0400


At 10:59 PM 11/5/2002 +0100, you wrote:

>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

Hmmm. Went there. Was referred to a file called *Errors.py* in Formulator. 
File doesn't exist. Noticed the thread was recent and the author was the 
author of the program. What did I miss?!

>
># 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)

Thank you! Yes, finally!

># 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'])

Okay, now I'm confused. What is this for?

>  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.

I did rewrite it.

Also, any idea on how to send *two* emails with slightly different content, 
all generated via Formulator, through the one connection to MailHost?
Thanks so much,
beno
P.S. Perhaps I should have called this thread "Still *Hacking* Away..."