Hello, I made a custom form based on Plone 6 documentation.
Edit: Corrected link.
configure.zcml
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="my.sandbox">
<browser:page
name="my-form"
for="*"
class=".my_form.MyForm"
permission="cmf.ManagePortal"
/>
</configure>
In my_form.py:
from plone import api
from plone import schema
from plone.autoform.form import AutoExtensibleForm
from z3c.form import button, form
from zope.interface import Interface
class IMyForm(Interface):
name = schema.TextLine(title = "Your Name"
)
class MyForm(AutoExtensibleForm, form.EditForm):
schema = IMyForm
ignoreContext = True
label="What's your name?"
description = "Simpe, sample form"
@button.buttonAndHandler("Ok")
def handleApply(self, action):
data, errors = self.extractData()
if errors:
self.status = self.formErrorsMessage
return
changes = self.applyChanges(data)
if changes:
self.status = "Settings changed"
@button.buttonAndHandler("Cancel")
def handleCancel(self, action):
print("TEST")
z = 0
y = 4 / z
self.request.response.redirect(api.portal.get().absolute_url())
The only real differences are I don't have the layer parameter for where I have the browser:page in configure.zcml and I have code to redirect to the front page in cancel.
When I click cancel, instead of redirecting to the front page, the name field gets an error message "Please fill out this field" and the cancel handler function isn't actually called. I tried a print statement and that didn't print in the terminal. I did try dividing by zero to trigger an error, but that was ignored.
Is it because I don't have the layer parameter in configure.zcml?
The cancel button is working in other forms. I went to add a Folder and clicked 'Cancel' and that worked as it should.