Form with only a submit button no longer allowed.

32 views
Skip to first unread message

David Manns

unread,
Sep 14, 2025, 9:03:11 AMSep 14
to py4web
I have long used a form with just a 'Checkout' button in conjunction with a grid that displays the current state of a registration (multiple guests):

form2 = Form(fields, formstyle=FormStyleBulma, submit_value='Checkout')



This is no longer allowed, but I think it's a legitimate use case.

Massimo DiPierro

unread,
Sep 14, 2025, 9:08:31 AMSep 14
to David Manns, py4web
Not sure I understand this use case. Nothing should have changed. At least not intentionally. Can you provide a minimal example so I can reproduce?

--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/6a15dff2-dee7-49f7-b627-09090741614cn%40googlegroups.com.

David Manns

unread,
Sep 14, 2025, 2:39:06 PMSep 14
to py4web
I can certainly create a _minimal example, but to illustrate my use case I attach a screen shot, and I propose a small change to form.py below.

Creating an event registration in my app involves creating individual records for a member(host) and, possibly, their guest(s). Sometimes there are selections (e.g., meal choices, ticket options) to be made per guest. So I use a grid to build the overall registration.

I use a separate form to create a checkout button to confirm the registration and make payment. Sometimes this form contains an input field (e.g. a "how did you hear of this event" multichoice survey), but more often the form is simply a way of creating a nice consistent checkout button.

The commit https://github.com/web2py/py4web/commit/025c34c85eda16afb846725bcfb2f087210c039a made major changes to form.py and in particular at line 1036 raises an error if there are no fields in a form.

Removing that test/raise and adding "not all_tablenames or " to the last line of the following selection seems to work, one can once again have a form with just a button:

if isinstance(table, list):
# using _table to check if Field.bind was called
# and the field is bound to a table, since unlike `tablename`, `_table` is
# only set in Field.bind()
all_tablenames = list(
set(
str(getattr(field, "_table", None) or "no_table") for field in table
)
)

# only disable dbio if the fields are from multiple tables
# this allows making forms for a subset of fields easily:
# Form([db.tbl.field1, db.tbl.field2])
if not all_tablenames or len(all_tablenames) > 1 or all_tablenames[0] in "no_table":


registration.png

Massimo DiPierro

unread,
Sep 14, 2025, 8:20:56 PMSep 14
to py4web
Understood. Implemented as you suggested

David Manns

unread,
Sep 15, 2025, 10:24:25 AM (14 days ago) Sep 15
to py4web
The fix works once the test and raise error are removed at form.py line 1036/7:
if isinstance(table, list):
fields_list = table
if len(fields_list) == 0:
raise ValueError("Cannot build form with empty list of fields")


Massimo DiPierro

unread,
Sep 16, 2025, 1:24:04 AM (13 days ago) Sep 16
to py4web
fixed
Reply all
Reply to author
Forward
0 new messages