Forum OpenACS Q&A: Example of a -validate block using template::element::create?

Hi all

I'm having trouble getting a -validate block working with template::element::create. I know it works with ad_form but the program I'm working with uses template::element::create. Is it possible to pass variables into the expression? It seems that $value is the only variable it can see.

Here's my code:
template::element::create $form_id default_org_contact_rel_p \
-label "Contact Rel P" \
-datatype text \
-widget checkbox \
-options $check_options \
-optional \
-validate {
only_one_allowed
{ db_string get_count $default_org_validation_sql }
"Only 1 relationship permitted"
}

Can anyone help?

thanks
Brian

Hi Brian, following works for me with OpenACS 5.7:

template::element::create $form_id phone \
    -optional \
    -label $phone_label \
    -html {size 15} \
    -datatype text \
    -maxlength 50 \
    -validate { check_test {
        expr 1 > 2
    } {
        "Failure"
    }}