I have a bit of a hard time finding a useful example of code for a viewlet with a custom z3c.form where users could send an inquiry about a product they are just seeing.
Please does somebody have a good pointer?
What is the question?
Writing a z3c.form based form does not differ from it usage in a portlet, a browser view or a viewlet...basically all the same.
I was not sure of what I was doing wrong. My viewlet looks following:
from Acquisition import aq_inner
from plone.app.layout.viewlets import ViewletBase
from plone.z3cform import z2
from plone.z3cform.interfaces import IWrappedForm
from plonetheme.vox.browser.forms.inquiry_form import InquiryForm
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from z3c.form.interfaces import IFormLayer
from zope.interface import alsoProvides
class InquiryViewlet(ViewletBase):
form = InquiryForm
index = ViewPageTemplateFile("inquiry-viewlet.pt")
def update(self):
super(InquiryViewlet, self).update()
z2.switch_on(self, request_layer=IFormLayer)
self.form = self.form(aq_inner(self.context), self.request)
alsoProvides(self.form, IWrappedForm)
self.form.update()
But I figured out the problem was in the InquiryForm because I had a template there:
class InquiryForm(AutoExtensibleForm, group.GroupForm, form.Form):
enableCSRFProtection = True
enable_form_tabbing = False
schema = IInquiryForm
form_name = "inquiry_form"
template = ViewPageTemplateFile('../templates/inquiry_form.pt')
[...]
After removing the template line, the viewlet started rendering fine. Is this supposed to be like that?