Good code Laurence. Thanks.
I wish we had a Cookbook to put all of these into. sucks unfortunately.

Laurence Rowe wrote:
I think you want to do something along these lines:

from zope.formlib import form
from zope.interface import Interface

class IEmailForm(Interface):
    subject = schema.TextLine(
    comments = schema.TextLine(

class EmailForm(form.Form):
    form_fields = form.Fields(IEmailForm)

    @form.action("Email", validator='validate_input')
    def handle_email_action(self, action, data):
        send_mail(data['subject'], data['comments'])
        self.status = u'Email Sent'

    def validate_input(self, action, data):
        #validation logic here
        return [] # no errors

def send_mail(subject, comments):

Plumb it in with zcml in the normal way. No idea about mutable schemas.

Hope that helps,


Graham Stratton wrote:
I have a seemingly simple problem. I want to provide a web form which is emailed off on submission. I'd like to do some validation before it is emailed off.

*snip saga involving much of formlib and browser:form*

On much reflection, I think what I probably want to do is to implement an 'email form' content type, which has an address to email the form to, and a schema, and then use the formlib machinery to produce and validate a form from this. Is this the right way to go? I can't work out how I can use any of the higher-level formlib code. Will I need to render one widget at a time and do my own validation? Or is there something useful in

I guess in the longer term it would make sense to make my schema persistent and based on the mutable schema implementation. How might I go about that? I did play a bit with the mutable schema utility, but I got errors when trying to add Text and TextLine fields. I also don't really understand why it's a utility anyway. Does it offer a way to edit any persistent schema?

I'm feeling very lost, I hope someone can point me in the right direction. Thanks for the all the support.



Zope3-users mailing list

Peter Bengtsson,
Zope3-users mailing list

Reply via email to