Re: form validation [off]
Re: form validation [off]
- Subject: Re: form validation [off]
- From: Michael Turner <email@hidden>
- Date: Tue, 12 Mar 2002 23:54:48 -0500
>
> Jessica,
>
>
>
> I don't use AS-cgi, so take this which ever way...
>
>
>
> I recommend Javascript for html-form validation before submission to
>
> any
>
> CGI. Validation in Javascript is easier and earlier (client-side).
>
>
>
> /Michael Turner
>
>
Yes, but I might add that JS validation is utterly useless without
>
complimentary server-side validation, for obvious reasons. (JS is
>
client-side, CGI is server-side.)
>
>
--
>
Michael
Michael,
I agree completely, re-validate on the server-side. Which leaves the
original question.
OK:
>
this is the behavior that I am after:
>
If a user enters an invalid response and hits submit,
>
a dialog box pops up, but the page does not redirect
>
The user hits "ok" and the invalid entry is erased from the page for
them
>
Then the user enters all valid data and hits submit, and they are
taken to a
>
different page thanking them (this page is also created by an acgi
script).
This behavior can and should be achieved with javascript. This is a
digression for the AppleScript list, so I will try to be brief. If you
would like a more-complete sample, please write me off-list. Not
everything written should be AS, but I guess everything on this list
should. Consider the script below to be an example of what AS doesn't
do. :-)
Create a javascript function and stick it in the html head. If you don't
know javascript, there are many freely available scripts on the web.
Something vaguely like this: (it can be done a million different ways)
<script language="javascript">
function validation()
{
if ( ! isEmail(document.feedback.email.value) )
// presumes another function to determine email validity
{
alert('Please type in a valid email address.');
// 'alert' is perfect for what you desire: a dialog box
document.feedback.email.focus();
// 'focus' will bring the users cursor that that portion of the
form
return false;
// doesn't submit to the cgi
}
else
{
return true;
// submits to the cgi
}
}
// just a sample, not a complete email validator //
</script>
then add the function to the form's 'action' like this:
<FORM NAME="feedback" method=POST onSubmit='return validator();'
ACTION="/cgi-bin/request.cgi">
What this script achieves is: when the user clicks "submit" without
entering an email address, the javascript intercepts the submission and
alerts the user to their mistake. When the user submits a valid form, it
checks it then submits as normal. Nothing needs to change on the
serverside to accomodate this, except that the javascript function needs
to be included in the html form that the server is providing. Sometimes
I get confused with the bizzard of different protocols and languages
this involves: HTML, javascript, cgi... all mixed together. But this
functionality would be more difficult (or just clumsy) from the server
side, its worth an investment in understanding.
You will need to re-validate with the AS-cgi because of possible
transmission errors. (And because everyone writes code which breaks.)
HTH
/Michael Turner
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.