[ic] Re: [data session errors] overwritten?

interchange-users@icdevgroup.org interchange-users@icdevgroup.org
Wed Jul 3 15:05:00 2002


I've posted this a few days ago, but haven't heard from anyone yet, 
not sure whether this post has made it successfully to the mailing 
list...  I'm sure someone has faced this kind of problems before... 
so, does anyone have any pointers in the right direction as to what 
could have gone wrong, or what I could do about it?  Really would 
appreciate any help!  TIA!


> I tried to use the following codes suggested by Bill (attached
> below for reference), and also wrote my own error check routine as
> a GlobalSub (also attached below) to verify if 2 email addresses
> are the same.  This custom error check routine is called in
> mv_order_profile, like this:
>
>
> [set my_account_profile]
> email=required
> email_confirm=required
>
> email=email
> email_confirm=email
>
> email=email_verification
> email_confirm=email_verification
>
> &fatal = yes
> [/set]
>
>
> <INPUT TYPE=hidden NAME=mv_order_profile VALUE=my_account_profile>
>
>
> However, it seemed that the $Session->{errors}{email} set by my
> GlobalSub has overwritten the previous Data Session Errors of the
> Email field, such that if both Email and Email_confirm fields are
> blank, they will not showing up in red at all to signify that
> they're blank, and not an email address, and do not match.
>
> If I change their orders, such that it is like this:
>
>
> [set my_account_profile]
> email=email_verification
> email_confirm=email_verification
>
> email=required
> email_confirm=required
>
> email=email
> email_confirm=email
>
> &fatal = yes
> [/set]
>
>
> when the 2 fields are blank, the errors show up in red alright, but
> when 2 different email addresses are entered, they're not compared,
> ie, email_verification doesn't seem to be called.  Either that, or
> it was called, but its Data Session Errors is overwritten (it
> seemed that way).
>
> Any pointers as to what could be wrong, and how I might overcome
> that?  Much thanks!
>
> -------------------------------------------------------------------
>-------------------- GlobalSub <<EOF
> sub set_up_extra_check {
>     BEGIN {
>         package Vend::Order;
>         sub _email_verification {
>             # $ref is to Vend::Session->{'values'} hash
>             # $var is the passed name of the variable
>             # $val is current value of checked variable
>             my($ref, $var, $val) = @_;
>
>             if ($ref->{email} ne $ref->{email_confirm}) {
>                 return (undef, $var, errmsg("Email addresses do not
> match"));
>               }
>               else {
>                 return (1, $var, '');
>               }
>         }
>     }
> }
> EOF
> -------------------------------------------------------------------
>-------------------- I quote:
> Bill Randle billr@exgate.tek.com
> Mon, 16 Oct 2000 10:53:23 -0700
>
>
> [set NewAccount]
> [set loginfail][/set]
> [tag flag write]userdb[/tag]
> [perl global=1]
>     # copy form vars from cgi to values, as [userdb new_account]
> requires
>     # that most of its vars be passed as values, rather than cgi
> vars.
>
>     ::update_values();
>
>     # check for empty fields
>     my @required_fields = (qw/
> fname   lname  address1 city
> state   zip    email    phone_day
> /);
>     for (@required_fields) {
>         if (! $Values->{$_}) {
>             $Vend::Session->{failure} =
>                 $Vend::Session->{errors}{$_} = "Required field $_
> is empty.";
>             $Scratch->{loginfail} = 1;
>         }
>     }
>     # attempt to validate the email address if no previous failures
>     if (! $Scratch->{loginfail} && $Values->{email} !~
>  /[\040-\176]+\@[-A-Za-z0-9.]+\.[A-Za-z]+/) {
>         $Vend::Session->{errors}{email} =
>             $Vend::Session->{failure} = "Badly formatted email
> address";
>         $Scratch->{loginfail} = 1;
>     }
> [/perl]
> mv_nextpage=new_account
> [if scratch loginfail]
> [log]new account not created[/log]
> [else]
> [if type=explicit compare="[userdb function=new_account log=1]"]
> [log]new_account create ok![/log]
> mv_nextpage=account
> [tag export userdb][/tag]
> [else]
> [log]new_account create failed![/log]
> [log interpolate=1][data session failure][/log]
> [/else]
> [/if]
> [/else]
> [/if]
> [/set]
>
> <P>
> [if type=explicit compare="[error all=1 show_var=1 keep=1]"]
>     <FONT COLOR=RED>One field was either empty, or contained wrong
> data.</FONT>
>     The fields are marked with <FONT COLOR=RED>this color</FONT>.
>     <P>
> [/if]
> [if session failure]
>     The error was:
>     <FONT COLOR=red>[loc][perl]$Vend::Session->{failure}=~s/\s+$//;
>  return $Vend::Session->{failure};[/perl][/loc]</FONT>
>     [data base=session field=failure value=""]
> [/if]
> <P>