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(
title=u'Subject',
required=True,
)
comments = schema.TextLine(
title=u'Comments',
required=True,
)
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,
Laurence
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 zope.app.form?
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.
Regards,
Graham
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users