While extremely powerful I think forms.py sometimes still has some way to go to be fully flexible.
Which is fine and only natural.
On the other hand there are well maintained battle proven html form renderers like wtforms that could maybe sometimes fill the gap?
Anyhow that is what I thought and I did a little PoC with wtforms and this works:
BTW: With wtforms you can to wrap the form object in the template in your own html <form method="post"> blog and use fields like you would use fields with a custom form from our forms.py
controller:
from py4web import action, request, abort, redirect, URL
from yatl.helpers import A
from .common import db, session, T, cache, auth, logger, authenticated, unauthenticated, flash
from wtforms import Form, BooleanField, StringField, validators, SubmitField
class RegistrationForm(Form):
email = StringField('Email Address', [validators.Length(min=6, max=35)])
submit = SubmitField ( " Send ")
@action("register", method=["POST", "GET"])
@action.uses(db, session, auth, "index.html")
def register():
form = RegistrationForm()
if request.method == 'POST':
email = request.forms.get('email')
print (email)
return dict(form=form)
template:
<form method="POST">
[[=form.email.label]]
[[=form.email]]
[[=form.submit]]
</form>