Forum OpenACS Development: template::form::set_error not working

Hi everybody,

This is a little nasty problem, but I have a form created with ad_form where I'm using the template::element::set_error or template::form::set_error in the -on_submit block to set a possible error in the form. The field widget is checkbox and it seems to me that the API is broken (I must be terribly wrong on that).

Checking the acs-templating/tcl/element-procs.tcl and acs-templating/tcl/form-procs.tcl files I see that the error is passed to the template::form::set_error and to template::element::set_error, but it's not passed away. The error message is stucked somewhere and it doesn't  go through the form, wich is rendered with no problem. Can anybody confirm that and please give some light?

By the way, I've just upgraded from oacs-5-2 to oacs-5-3, and all my files versions use that tag.

Collapse
Posted by Claudio Pasolini on
Are you sure that the form and element id are correct?
The template::form::set_error API works regularly in my oacs-5-3.
Collapse
Posted by Eduardo Santos on
Yes, I'm sure. I've tried the same thing in a different form and it didn't work either. This is my form declaration:
ad_form -name area -cancel_url "one?organization_id=$organization_id" -export {
    organization_id
    organization_type_selected
    country_iso
} -form {
    {organization_type:text(select) {label "<span>#</span>organizations.Org_type#"} {options $organization_types} {value $organization_type_selected} {help_text "[_ organizations.Area_change_help]"} }
    {main_state:text(text) {label "<span>#</span>organizations.Main_state#"} {mode display} {help_text "[_ organizations.Main_state_help]"}}
    {states:text($widget),multiple,optional {label "<span>#</span>organizations.States#"} {options $state_options} {values $states_selected}}

This is the error call:

} -on_submit {
    if {[lsearch {2 4 5} $organization_type] ne -1 && $states eq ""} {
        template::form::set_error "area" "states" "Required"
    }
Collapse
Posted by Dafydd Crosby on
You need to add a break statement to stop the rest of the form from going.

Revised:
} -on_submit {
    if {[lsearch {2 4 5} $organization_type] ne -1 && $states eq ""} {
        template::form::set_error "area" "states" "Required"
        break
    }
}

Collapse
Posted by Ryan Gallimore on
Put your validation in a -validate block. template::form::set_error is then called implicitly.