Here's an idea: Add an optional declaration block to ad_page_contract, called -form, that contains all widget declarations that the form will be built of, which were previously declared in ad_form. The same filters as for usual ad_page_contract variables can be applied, e.g. integer, trim, html, etc.
The main difference will be that upon initial request the existance of those variables will not be checked - only when the request is a submitted form.
The ability to specify the key variable in ad_page_contract needs to be added, either in the vars block or in -form. Example:
ad_page_contract {
add or edit a note
} {
note_id:key
} -form {
{ title:trim
{html { size 20 }}
{label "Title"}}
{ body:text(textarea),trim
{label "Body"}
{html { rows 10 cols 40 wrap soft }}}
}
This way ad_page_contract would already know if the form is a new or edit
request, and can supply that knowledge by setting a variable like __new_p that
will be defined for every request when a -form block is present, not
only upon invalid form redisplays. No more need to add kludges like ad_form_new_p.
I don't know how dynamic form building with ad_form -extend would fit in here. Dynamically generated variables obviously can't be part of ad_page_contract (assuming no one wants to put code before it, which would be ugly).
To avoid clutter in the -form block there should be the possibility to refine the widgets declaration later in the page, and leave stuff like {html ...} completely out of ad_page_contract.
Also it would be nice if form element errors that will be displayed inline could be manually set in the code, e.g. in the -validate clause of ad_page_contract, and if there was the possibility to generate generic validation messages that are not associated to a specific element but still would be displayed inline, instead of the current "Please press back and correct ..." message.
This is a terribly chaotic pile of thoughts, but hopefully enough to start a discussion.
Request notifications