[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date
][Minivend by thread
]
Re: [mv] Using JavaScript to validate a form
****** message to minivend-users from Brian Wright <bdw@aturna.com> ******
Hi, Bill..
Yes, I'm using MV3, sorry for not mentioning that previously. <blush blush> :)
Would this example work for MV3?
--Brian
On 21-Mar-2000 Bill Randle wrote:
> ****** message to minivend-users from "Bill Randle" <billr@exgate.tek.com>
> ******
>
> Brian,
>
> You don't mention whether you're using MV4 or MV3. On the off chance
> that you're using MV4, you can actually use minivend to do the
> validation for you, using order profiles, rather than writing a
> JavaScript program to do it. This is actually kind of nice, because
> the minivend check routines will not only check for the presence
> or absense of a field, but can also validate the contents. I.e., it
> can check that zip is a valid zip code, email is a valid email
> address, etc.
>
> In the example below, I've put the order profile inline, but you can
> can put it in, e.g., etc/profiles.login instead (actually, there's
> one there already). In any event, here's what I use on my account
> creation and modification pages (with a modified version of your
> form setup):
>
> [set NewAccount]
> fname=required
> lname=required
> city=required
> state=state_province
> zip=postcode
> phone_day=required
> phone_day=phone_us
> address1=required
> email=required
> email=email
> &fatal=yes
> &set=mv_successpage @@MV_PREV_PAGE@@
> &set=mv_failpage @@MV_PAGE@@
> &set=login_status [if type=explicit compare="[userdb function=new_account]"]
> [then]1[/then]
> [else] [set login_failure]1[/set] [/else]
> [/if]
> [/set]
>
> [comment]
> There are two sources of error: errors in filling out the form
> (missing fields, badly formed email address, etc.) and an error
> saving the data to the userdb database. In the second case, the
> error message is stored in session failure; in the first case
> the error message(s) are stored as a hash in session error.
> [/comment]
>
> [mvasp]
> <%
> my @acctvars = qw( fname lname city
> state zip phone_day
> address1 email );
> my $var;
> my @errors;
> foreach $var (@acctvars) {
> if ($Session->{errors}{$var}) {
> push @errors, $Session->{errors}{$var};
> }
> }
> if ($#errors >= 0) {
> $Session->{failure} = join '\n', @errors;
> $Scratch->{login_failure} = 1;
> }
> %>
> [/mvasp]
>
> <p>
> [if scratch login_failure] [set login_failure][/set]
> <b>Your account was not created for the following reason:</b><br>
> <blockquote>
> <font color="red"><b>[data session failure]</b></font>
> </blockquote>
> <p>Please try again. If there are problems you can't correct, please contact
> us.
> [/if]
>
> <form ACTION="[process-target secure=1]" METHOD="POST">
> <input TYPE="hidden" NAME="mv_order_profile" VALUE="NewAccount">
> <input TYPE="hidden" NAME="mv_todo" VALUE="submit">
> <input TYPE=hidden NAME="mv_nextpage" VALUE="[data session
> prev_url]">
>
> (form fields here)
>
> <INPUT TYPE=submit VALUE="Create Account" SIZE=10>
>
>
> -Bill Randle
> billr@exgate.tek.com
>
>
> On Mar 20, 4:52pm, Brian Wright wrote:
> } Subject: [mv] Using JavaScript to validate a form
> } ****** message to minivend-users from Brian Wright <bdw@Aturna.com>
> ******
> }
> } Hello, listees. :)
> }
> } I'm trying to use JavaScript to validate and submit a form. However, the
> alert
> } box does not pop up if you omit a field. Here's a code snippet:
> }
> } [set NewAccount]
> } [userdb function=new_account ignore_case=1]
> } [if session failure]
> } [data session failure]
> } [else]
> } [userdb save]
> } [tag export userdb userdb.asc]Proceed[/tag]
> } [/else]
> } [/if]
> } [/set]
> } <SCRIPT LANGUAGE="JavaScript">
> } <!--
> } function validateForm(form)
> } {
> } if (form.name.value == "")
> } {
> } alert("You have not filled in the Name field.");
> } form.name.focus();
> } return false;
> } }
> } else if (form.address.value == "")
> } {
> } alert("You have not filled in the Address field.");
> } form.address.focus();
> } return false;
> } }
> } else if (form.city.value == "")
> } {
> } alert("You have not filled in the City field.");
> } form.city.focus();
> } return false;
> } }
> } else if (form.state.value == "")
> } {
> } alert("You have not filled in the State field.");
> } form.state.focus();
> } return false;
> } }
> } else if (form.zip.value == "")
> } {
> } alert("You have not filled in the Zip field.");
> } form.zip.focus();
> } return false;
> } }
> } else if (form.email.value == "")
> } {
> } alert("You have not filled in the E-mail field.");
> } form.email.focus();
> } return false;
> } }
> } else if (form.phone_day.value = "")
> } {
> } alert("You have not filled in the Daytime Phone field.");
> } form.phone_day.focus();
> } return false;
> } }
> } }
> } -->
> } </SCRIPT>
> }
> }
> } <form ACTION="[process-target secure=1]" METHOD="POST">
> } <input TYPE="hidden" NAME="mv_check" VALUE="NewAccount">
> } <input TYPE="hidden" NAME="mv_doit" VALUE="return">
> } <input TYPE="hidden" NAME="function" VALUE="new_account">
> } <INPUT TYPE=hidden NAME="mv_nextpage" VALUE="[data session
> prev_url]">
> }
> } (form fields here)
> }
> } Then, I use the following to submit:
> }
> } <INPUT TYPE=submit VALUE="Create Account" SIZE=10 onSubmit="if
> } (validateForm(this.form)){this.form.submit()}">
> }
> } But, it doesn't catch an empty form field. :(
> }
> } --Brian
> }
> }
> }
> } _________________________________________________________________________
> } Brian Wright Aturna Communications Inc.
> } bdw@aturna.com Internet Services
> } WWW http://www.aturna.net
> } _________________________________________________________________________
> } -
> } To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
> } email with 'UNSUBSCRIBE minivend-users' in the body to
> Majordomo@minivend.com.
> } Archive of past messages: http://www.minivend.com/minivend/minivend-list
> }-- End of excerpt from Brian Wright
>
>
> -
> To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
> email with 'UNSUBSCRIBE minivend-users' in the body to
> Majordomo@minivend.com.
> Archive of past messages: http://www.minivend.com/minivend/minivend-list
_________________________________________________________________________
Brian Wright Aturna Communications Inc.
bdw@aturna.com Internet Services
AIM: BigBY2K ICQ: 21221328 WWW http://www.aturna.net
_________________________________________________________________________
-
To unsubscribe from the list, DO NOT REPLY to this message. Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list