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

Collapse
Posted by Don Baccus on
Dave ... ad_form handles two-part form scripts with a confirm page without any problem (check out "confirm_template"). Of course exactly duplicating the existing forums behavior might be a bit tricky ...

My examples are always self-submit scripts because that means you only have to define or change form element definitions in one place. This is also why I tried to make it easy to write single scripts that handle editing of existing data and the insertion of new data.

Shared code is good ... if it's not overwhelmingly complex, and my hope is that the ad_form wrapper simplifies stuff to the point where this style is simpler than the alternative.

Jeff ... yes, single-value validation is done as you describe. I was assuming that Dave tried writing an ad_form validation block, checking the html_p widget and if set true then transforming the data string to HTML (which doees a html security check) otherwise transforming it to text.

ad_form's validation block is executed from within ad_form, not the form builder itself ...

In ad_form the way you pin an error to a particular form element when you're doing a composite check is to give that form element's name as the tag to the validation snippet. Simple datatype validation errors are handled by the form builder and of course pinned to the element that triggers it.

    {end_date
        { [template::util::date::compare $end_date $start_date] > 0 }
        "End date must be after the start date"
    }
This example checks that an end date follows a start date, and pins the error to the end date field. If I wanted to pin it to the start date element I'd change the "end_date" tag to "start_date" - and presumably rewrite the error message to reflect this.