[ic] Address book and profile handling

Ron Phipps interchange-users@icdevgroup.org
Tue Aug 20 03:24:01 2002


> From: Dan Browning
> 
> At 04:51 PM 8/19/2002 -0700, you wrote:
> >Hello,
> >
> >Using IC 4.8.3 on RH 7.2, PostgreSQL, Apache.
> >
> >I have the following profile:
> >
> >__NAME__                            shipping_account_change
> >fname=required First Name is required
> >lname=required Last Name is required
> >address1=required Address is required
> >city=required City is required
> >country=required Country is required
> >[if value country =~ /^(US|CA)$/i]
> >         state=state_province
> >         zip=postcode Zip/Postal Code is not valid (ex: 12345 or
> >12345-1234)
> >[/if]
> >phone_day=required Phone is required
> >&fatal = yes
> >phone_day=phone Phone number is not valid (ex: 800-555-555)
> >__END__
> >
> >Which is invoked by a form with the following line:
> >
> ><INPUT TYPE=hidden NAME=mv_form_profile
VALUE=shipping_account_change>
> >
> >The form also contains all the fields which make up a shipping
address.
> >
> >The values are saved by this button:
> >
> >                                 [button
> >                                         text="Save"
> >                                         src="buttons/save.gif"
> >                                         hidetext=1
> >                                         form=ship_address
> >                                 ]
> >                                         mv_check=save_shipping
> >                                 [/button]
> >
> >And save_shipping is as follows:
> >
> >[set save_shipping]
> >[value name=s_nickname set="[cgi s_nickname]" filter="nullselect
> >no_white" hide=1]
> >[userdb function=set_shipping
>
>shipping="s_nickname,company,fname,lname,address,address1,address2,city
,
> >state,zip,country,phone_day"]
> >[/set]
> >
> >The profile works correctly and will present the error(s) if a
problem
> >is encountered.  If no errors are encountered then the address is
saved
> >to the shipping address book.  The problem arises when errors are
> >encountered.  If a user forgets to put in their phone, but fills out
> >everything else correctly then the form will be displayed with the
> >error, but the values which are ok will be reverted back to the last
> >saved value.  This is frustrating to the user because they should not
> >have to re-enter everything just because one field failed.
> >
> >Is it possible to have the profile check for errors and allow the
values
> >to be updated, but not do the userdb set_shipping if there is an
error?
> >This would allow the user to see the errors, but not have their
changes
> >lost.
> >
> >Thanks,
> >-Ron
> 
> Check out this CVS commit by Mike Heins:
> 
> User:      heins
> Date:      2002-06-25 03:18:09 GMT
> Modified:  lib/Vend Order.pm
> Log:
> * Add &update=[yes|no] to automatically update a values variable
>    upon checking good. Usually useful for mv_form_profile.
>    Example:
> 
> 
>          [set tprof]
>          &fail=@@MV_PAGE@@
>          &update=yes
>          &fatal=no
>          name=required
>          addr=required
>          email=email
>          [/set]
> 
> 
>          <FONT color="red">
>                  [error all=1 show_error=1 show_label=1 joiner="<br>"]
>          </font>
> 
> 
>          <form action="[area index]">
>          <input type=hidden name=mv_action value=back>
>          <input type=hidden name=mv_failpage value="@@MV_PAGE@@">
>          Name <input name=name value="[value name]"><br>
>          Addr <input name=addr value="[value addr]"><br>
>          Email<input name=email value="[value email]"><br>
>          <input type=submit>
>          </form>
> 
> 
>    As the variables check good, they will be updated.
> 

Thanks Dan,

I'll take a look at this and see how it goes.  My only concern at this
point is also preserving the values that did not check out correctly.
For example let's say the form is already filled out and has been saved
with all fields being ok.  Then the user comes back and decides to
change their zip code from 99999 to 1111, when the form is saved it is
going to go through the profile and see that 1111 is not a valid zip
code, revert 1111 back to 99999 and present an error message to the user
that says 'Invalid zip code.....'.  The user has now lost the 1111 they
already entered.  It's almost like I need the form to go back to the
exact state it was before the user pressed save even if the values are
incorrect.  I'm not sure I can do this with a profile, however it may be
possible if I put a required check before the format check for each
field with update=yes.  The other gotcha is if the form has been saved
and the user erases one of the required fields and then saves.  The user
will get a message that says 'Field is required', but when they look at
the field they will see it is filled in because it reverts back to the
last updated value.  Maybe I can come up with a 'check' for the field
that always returns true with update=yes and fool the profile into
saving the values, that way the values will always be updated, but the
changes will not be saved unless no errors are encountered.

I'll post back and let you know how it went, thanks again!

-Ron