Forum OpenACS Q&A: Re: Validating form elements with the form builder

Collapse
Posted by alex vorobiev on
i found this thread and figured that my question would be somewhat relevant.

i am trying to figure out various ways to validate form input data in openacs.

1) via ad_page_contract: this one displays a brief error message and instructs user to use the back button;

2) ad_form validate flag, does this one actually invoke form::element validate, or does it's own validation?

3) form::element validate flag;

finally, i am looking at
https://openacs.org/doc/acs-templating/demo/sandwich,
where the form has inline validation, ie the form is redisplayed with specific error messages.  yet, looking at the code, none of the above options are being used.  what i have noticed that the only field that doesn't generate a validation error when not populated, vitamins, has a -optional flag to from::element.

hence my questions:
1) in the acs-template docs the form::element actually is not documented as having such a flag available; the form::request, however, does...  out-of-date documentation, or does form::element pass the flag onto request (just guessing here, without detailed knowledge of the code).

2) if ad_form is just a wrapper around form templ. functions, is the -optional flag getting set for all elements by default?  in other words, it seems like no validation takes place in ad_form unless i explicitly create validation blocks.  so, i am trying to figure out how the -optional flag factors into this (as in the sandwich example above).

thanks for all your help and patience,

--sasha

Collapse
Posted by alex vorobiev on
re my question #2): it looks like if i take out the variable from the ad_page_contract, then i get nice inline validation error message through ad_form.

as a related question: i am assuming then that all elements added via ad_form are considered required unless specified otherwise; if so, why don't i see red stars next to required elements, since it should be true by default as per roberto mello's ad_form reference sheet...

--sasha

Collapse
Posted by Jade Rubick on
Alex, I don't know the answer to that. Since nobody is responding here, perhaps you can ask on IRC, and follow up here if you find it out?