On Mon, 29 Oct 2001, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote,

> Hi
>
> Before I learned about HTML::Template, I wrote something similar myself, for
> my company. Ok, the "parser" sucked, but the functionality had a couple of
> things I'd like to see in H::T as well:
>
> - Most of all, it should be possible to compare a variable to some value
> instead of it just being Boolean. Something like <TMPL_IF
> NAME="PARAMETER_NAME" VALUE="PARAMETER_VALUE"> </TMPL_IF>.
>   <TMPL_IF NAME="ERROR" VALUE="NO_FIRST_NAME">Please enter your first
> name.</TMPL_IF>
>   <TMPL_IF NAME="ERROR" VALUE="NO_LAST_NAME">Please enter your last
> name.</TMPL_IF>

I have a slightly different implementation for this error handling.  I also
define all possible errors in the template with a series of TMPL_IF, but I
use numbering, so I have,

<TMPL_IF has_error>
<p class=error_message>
Hey dude, you have some problems,
<ol class=error_list>
<tmpl_if error_1><li>Don't have firstname?</tmpl_if>
<tmpl_if error_2><li>Are you kidding? Or just hiding your lastname?</tmpl_if>
<tmpl_if error_3><li>You haven't shaved your beard!</tmpl_if>
</ol>
</p>
</TMPL_IF>

When processing the form, I examine the value I need to examine and push
numbers to @errnum corresponding to the value for each error.  And then,

    # assuming %param is defined somewhere
    if (@errnum) {
        $param{has_error} = 1;
        $param{"error_$_"}++ foreach @errnum;
        go_back_display_the_form_along_with_the_error_messages();
    }

Validating values is the duty of the application, not HTML::Template,
I believe.

> - Following this idea further, one should also be able to choose the
> operator: LT, GT, LE, GE, EQ (default), NE  (if the value is a string, use
> string comparison, otherwise numeric comparison):
>   <TMPL_IF NAME="FIRST_NAME" VALUE="John">Hi, John!</TMPL_IF>
>   <TMPL_IF NAME="NUMBER_OF_KIDS" VALUE="5" OPERATOR="GE">So, you have a lot
> of children?</TMPL_IF>
>
> - And while we're at it: Why not allow Regular Expressions? :-)
>   <TMPL_IF NAME="STATE" VALUE="(CA|NY|TX)" OPERATOR="REGEX">Residents of
> California, New York or Texas please add 5% tax.</TMPL_IF>
>   (No, I have no clue about US taxes...)

Well, I think you want HTML::Template::Expr for this.


san
-- 
Trabas - http://www.trabas.com



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to