Home
The Toolkit for Online Communities
15938 Community Members, 0 members online, 2299 visitors today
Log In Register

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

OpenACS Home : Forums : OpenACS Development : Re: template::form::set_error not working : One Message

+
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.
+
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 "MESSAGE KEY MISSING: 'organizations.Org_type'"} {options $organization_types} {value $organization_type_selected} {help_text "[_ organizations.Area_change_help]"} }
{main_state:text(text) {label "MESSAGE KEY MISSING: 'organizations.Main_state'"} {mode display} {help_text "[_ organizations.Main_state_help]"}}
{states:text($widget),multiple,optional {label "MESSAGE KEY MISSING: '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"
}

+
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
    }
}

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