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

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.