Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Newbie Question: JS for Comparing Email Fields...Use with CGI Script??

Reply
Thread Tools

Newbie Question: JS for Comparing Email Fields...Use with CGI Script??

 
 
bateman5
Guest
Posts: n/a
 
      02-11-2004
Hi. Here's the situation. I have a very well-working form that acts as
a questionnaire. Im using AlienForm 2, CGI script because it is a
looong, multi-page form. All is working well, but we are getting wrong
email addresses. The CGI script validates that the email format is
correct (with @ and .), but the user can still mistype the address. We
want to ad a "Confirm Email" field. Can I do this with a snippet of
JavaScript code and not mess up my CGI script? I'd like it to alert
the user before it even reaches the script. Any help and enlightenment
on this would sure be appreciated!
 
Reply With Quote
 
 
 
 
Brian Genisio
Guest
Posts: n/a
 
      02-11-2004
bateman5 wrote:
> Hi. Here's the situation. I have a very well-working form that acts as
> a questionnaire. Im using AlienForm 2, CGI script because it is a
> looong, multi-page form. All is working well, but we are getting wrong
> email addresses. The CGI script validates that the email format is
> correct (with @ and .), but the user can still mistype the address. We
> want to ad a "Confirm Email" field. Can I do this with a snippet of
> JavaScript code and not mess up my CGI script? I'd like it to alert
> the user before it even reaches the script. Any help and enlightenment
> on this would sure be appreciated!



It all depends on what you are looking to do on the client side. In
Javascript, you can check to make sure there is an @ symbol, and a .
symbol (see indexOf). That is a simple test you can attach to the
onSubmit event of the FORM tag.

If you want to verify that the domain exists, there is no reliable way
to do it with JavaScript. If you want to verify that the email address
exists, the only reliable way to do that, is to send them a message
(from your CGI app) that they need to reply to.

Brian

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      02-12-2004
Brian Genisio wrote:

> bateman5 wrote:
>
>> Hi Brian,
>>
>> My CGI script already confirms that the format is in email syntex
>> ((E-Mail Removed)). I would rather just check to make sure it is
>> entered correctly to insure there are no typos. Thus, my interest in a
>> script that compairs two fields to make sure they match, client side.
>> Is that possible? Thanks!

>
>
> Yes, it is possible. What, excactly, are you trying to compare? Two
> text fields? Can you give a code example?
>
> Javascript has the ability to compare data. You cannot, however, verify
> that an email address exists, without sending it a message (from the
> server), and receiving a response back.


That depends on your definition of a "response back". If I use my AOL
Email address and send an email to
someObviouslyNonExistentEmailAddress...tentDomain.com
then I will get a "response back". But it doesn't confirm the existence
of the address. The response I get is a mailerDaemon message telling me
it was undeliverable but its *still* a "response back".

Conversely, if I send an email from my Comcast email address to an
invalid AOL address, I will still get a response back, but not a
confirmation that the address exist.



--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

 
Reply With Quote
 
bateman5
Guest
Posts: n/a
 
      02-12-2004
Hi Brian,

My CGI script already confirms that the format is in email syntex
((E-Mail Removed)). I would rather just check to make sure it is
entered correctly to insure there are no typos. Thus, my interest in a
script that compairs two fields to make sure they match, client side.
Is that possible? Thanks!
 
Reply With Quote
 
Brian Genisio
Guest
Posts: n/a
 
      02-12-2004
bateman5 wrote:

> Hi Brian,
>
> My CGI script already confirms that the format is in email syntex
> ((E-Mail Removed)). I would rather just check to make sure it is
> entered correctly to insure there are no typos. Thus, my interest in a
> script that compairs two fields to make sure they match, client side.
> Is that possible? Thanks!


Yes, it is possible. What, excactly, are you trying to compare? Two
text fields? Can you give a code example?

Javascript has the ability to compare data. You cannot, however, verify
that an email address exists, without sending it a message (from the
server), and receiving a response back.

Brian

 
Reply With Quote
 
bateman5
Guest
Posts: n/a
 
      02-15-2004
Robert <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> There are some challenges with your request.
>
> You have a pre-built set of forms and the server program. You indicated
> that you would prefer that you not change your server code. You can go
> and modify the web pages. This could impact your server code if you add
> more forms fields. Once you go an modify the downloaded pages, you may
> not be able to use you web page genearation program because it may
> discard your changes.
>
> There is the question of the user interface. What impact will you be
> having on how the forms are displayed.
>
> Here is what you could do. You could ask the user to confirm the userid
> with the window.prompt method.
>
> <form name=myform
> ACTION="http:// ... "
> METHOD="POST" onSubmit="adjustID()">
>
> ...
>
> <SCRIPT type="text/javascript">
> function adjustID()
> {
> var answerID = window.prompt("Please type your userid again.","");
> //Compare the two userid. Prompt again if you need too.
>
> }
>
> </script>
>
> Another alternative...
>
> You could add another field to the form and have the user type in the
> userid twice. You could compare the two userids in onSubmit event. You
> could prompt for a correction if needed. I believe if you set the field
> with the second typing of the user id to "" that the "" field will not
> be sent to the server.
>
> Note in both cases once the onSubmit javascript code completes the form
> will be posted. You can change the HTML code to allow you to post from
> Javascript. Some posters in this forum do not like to do that because
> if the user turns of javascript in the browser, the user will not be
> able to use your forms.
>
> If someone has turned off scripts in their browser, you can add the code
> <noscript>
> <!--
> Generate html source for those folks with scripting turned off
> -->
>
> </script>
>
> Also, people have sample Javscript functions around the web for
> verifying the format of a userid is valid.
>
> Robert


Robert, thank you for the reply and suggestion. My question is still a
very specific one, where the rubber meets the road! Where in my code
do I put the <form> and <script> code that you suggested? Im having
trouble making it work with my exisiting code that posts the form to a
cgi script. Here is the web address if you want to take a look at my
current code. Do I just insert the new code to compare around the
fields I want it to include (the email and confirm email fields). Not
sure if it nests inside the original <form> codes. Thanks for your
help!

http://nurturingnetwork.org/clientqu...entquesta.html

NB
 
Reply With Quote
 
bateman5
Guest
Posts: n/a
 
      02-15-2004
Brian Genisio <(E-Mail Removed)> wrote in message news:<402b9639$1@10.10.0.241>...
> bateman5 wrote:
>
> > Hi Brian,
> >
> > My CGI script already confirms that the format is in email syntex
> > ((E-Mail Removed)). I would rather just check to make sure it is
> > entered correctly to insure there are no typos. Thus, my interest in a
> > script that compairs two fields to make sure they match, client side.
> > Is that possible? Thanks!

>
> Yes, it is possible. What, excactly, are you trying to compare? Two
> text fields? Can you give a code example?
>
> Javascript has the ability to compare data. You cannot, however, verify
> that an email address exists, without sending it a message (from the
> server), and receiving a response back.
>
> Brian


Brian,

Thanks for your time. I am trying to compare two email fields, "email
address" and "confirm email address" because we keep getting typos.
The nature of the form is one that whoever is filling it out wants to
be contacted (it is a cherity organization) and wont most likely enter
bogas emails. So the errors are mostly typos, Im assuming. Im not
concern with verifying an email exists as much as accurate typing. The
site address is

http://nurturingnetwork.org/clientqu...entquesta.html

if you have time to look at my code. Im just confused how to make a
javascript run with the cgi script already in place. Thanks so much!

NB
 
Reply With Quote
 
Brian Genisio
Guest
Posts: n/a
 
      02-16-2004
bateman5 wrote:
> Brian Genisio <(E-Mail Removed)> wrote in message news:<402b9639$1@10.10.0.241>...
>
>>bateman5 wrote:
>>
>>
>>>Hi Brian,
>>>
>>>My CGI script already confirms that the format is in email syntex
>>>((E-Mail Removed)). I would rather just check to make sure it is
>>>entered correctly to insure there are no typos. Thus, my interest in a
>>>script that compairs two fields to make sure they match, client side.
>>>Is that possible? Thanks!

>>
>>Yes, it is possible. What, excactly, are you trying to compare? Two
>>text fields? Can you give a code example?
>>
>>Javascript has the ability to compare data. You cannot, however, verify
>>that an email address exists, without sending it a message (from the
>>server), and receiving a response back.
>>
>>Brian

>
>
> Brian,
>
> Thanks for your time. I am trying to compare two email fields, "email
> address" and "confirm email address" because we keep getting typos.
> The nature of the form is one that whoever is filling it out wants to
> be contacted (it is a cherity organization) and wont most likely enter
> bogas emails. So the errors are mostly typos, Im assuming. Im not
> concern with verifying an email exists as much as accurate typing. The
> site address is
>
> http://nurturingnetwork.org/clientqu...entquesta.html
>
> if you have time to look at my code. Im just confused how to make a
> javascript run with the cgi script already in place. Thanks so much!
>
> NB


Yes... very simple... I did not test this, but it should work for you.
When they press submit, it will check the addresses for you. If they
are not the same, an alert will inform them that there was an error, and
the form will NOT submit. If they are the same, the form will submit
without incident.

In this line:
<form METHOD="POST"
ACTION="http://www.nurturingnetwork.org/cgi-bin/clientquest.cgi">

Change to the following:
<form METHOD="POST"
ACTION="http://www.nurturingnetwork.org/cgi-bin/clientquest.cgi"
onSubmit="return formValidate()">

Then, in the head, add the following:

<SCRIPT>
function formValidate()
{
var success = true;

if(document.getElementById)
{
if(document.getElementById &&
(document.getElementById("e_email").value !=
document.getElementById("e_confirmed_email").value ))
success = false;
}
else if (document.all)
{
if(document.all &&
(document.all.e_email.value !=
document.all.confirmed_email.value))
success = false;
}

if(!success)
{
alert("Sorry, email addresses do not match. Please try again");
return false;
}

return true;
}




 
Reply With Quote
 
Robert
Guest
Posts: n/a
 
      02-16-2004
> Robert, thank you for the reply and suggestion. My question is still a
> very specific one, where the rubber meets the road! Where in my code
> do I put the <form> and <script> code that you suggested? Im having
> trouble making it work with my exisiting code that posts the form to a
> cgi script. Here is the web address if you want to take a look at my
> current code. Do I just insert the new code to compare around the
> fields I want it to include (the email and confirm email fields). Not
> sure if it nests inside the original <form> codes. Thanks for your
> help!
>
> http://nurturingnetwork.org/clientqu...entquesta.html
>
> NB


I noticed that you are working with a charity. That motivated me to
write the folowing example.

If you server application doesn't ignore the second userid field try
inserting this line at the end of checkEmail:
document.forms[0].e_confirmed_email.value = '';
or you can try inserting:
document.forms[0].e_confirmed_email.value = null;
One of these and I think it is the first will prevent the field from
being set to the host.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>clientquesta</TITLE>

<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=iso-8859-1">

<SCRIPT type="text/javascript">

function diffEmail()
{

// If the person enters two email address, verify that they
// are both the same.
// This doesn't for the person to enter either one or make
// them the same.
if (document.forms[0].e_email.value != ""
&& document.forms[0].e_confirmed_email.value != ""
&& document.forms[0].e_email.value !=
document.forms[0].e_confirmed_email.value)
{
// Put out an alert to suggest the person fix the email address
alert("Your confirmation email address differs from you email"
+ " address. "
+ "Please correct your email address.");
}
}

function checkEmail()
{
var i;

if (document.forms[0].e_email.value !=
document.forms[0].e_confirmed_email.value)
{
// Try getting a matching userid up to three times.
for (i=1;i<4;i++)
{
// Ask the person to try again.
userEmail = window.prompt("Your confirmation email address"
+ " differs from you email"
+ " address."
+ " Please enter your correct email address address.","");
if (document.forms[0].e_email.value == userEmail)
{
document.forms[0].e_confirmed_email.value = userEmail;
break;
}
else if (document.forms[0].e_confirmed_email.value == userEmail)
{
document.forms[0].e_email.value = userEmail;
break;
}
else
{
// We didn't find a match. Change an arbitrary email
// address and ask the user again.
document.forms[0].e_confirmed_email.value = userEmail;
}
}
}
}

</script>

</HEAD>
<BODY>


<br><br><br><br><br><br>

<FORM METHOD="POST" ACTION="http:error"
onSubmit="checkEmail();">

<TABLE ALIGN="center" BORDER=0 CELLSPACING=0 CELLPADDING=0
WIDTH="600">


<TR><TD></TD><TD WIDTH=220><BR>Email address</TD>

<TD COLSPAN=2 WIDTH=370><BR><INPUT
TYPE="text" NAME="e_email" Size=60 onBlur="diffEmail();"></TD></TR>

<TR><TD></TD><TD WIDTH=220><BR>Confirm Email address</TD>

<TD COLSPAN=2 WIDTH=370><BR><INPUT
TYPE="text" NAME="e_confirmed_email" Size=60
onBlur="diffEmail();"></TD></TR>

<TR><TD></TD><TD WIDTH=220><BR>another field</TD>

<TD COLSPAN=2 WIDTH=370><BR><INPUT
TYPE="text" NAME="anotherField" Size=60 ></TD></TR>


</TABLE>
<input type="submit" value="Submit form">
</FORM>

</BODY>

</HTML>
 
Reply With Quote
 
bateman5
Guest
Posts: n/a
 
      02-17-2004
Brian Genisio <(E-Mail Removed)> wrote in message news:<4030bda4@10.10.0.241>...

> Yes... very simple... I did not test this, but it should work for you.
> When they press submit, it will check the addresses for you. If they
> are not the same, an alert will inform them that there was an error, and
> the form will NOT submit. If they are the same, the form will submit
> without incident.
>
> In this line:
> <form METHOD="POST"
> ACTION="http://www.nurturingnetwork.org/cgi-bin/clientquest.cgi">
>
> Change to the following:
> <form METHOD="POST"
> ACTION="http://www.nurturingnetwork.org/cgi-bin/clientquest.cgi"
> onSubmit="return formValidate()">
>
> Then, in the head, add the following:
>
> <SCRIPT>
> function formValidate()
> {
> var success = true;
>
> if(document.getElementById)
> {
> if(document.getElementById &&
> (document.getElementById("e_email").value !=
> document.getElementById("e_confirmed_email").value ))
> success = false;
> }
> else if (document.all)
> {
> if(document.all &&
> (document.all.e_email.value !=
> document.all.confirmed_email.value))
> success = false;
> }
>
> if(!success)
> {
> alert("Sorry, email addresses do not match. Please try again");
> return false;
> }
>
> return true;
> }


How can I ever thank you??? The form works perfectly! Just what we
needed. I feel like I need to bake you cookies or something! Can you
attach those to a Google group?? I really really appreciate all of
your help (everyone). Sometimes this code stuff goes beyond the scope
of this graphic/web designer's brain. Anything between <SCRIPT> and
</SCRIPT> is a bit foreign to me! Anyway, thanks so much for your time
and very well written explanations. It may have been simple for you,
but it was a great solution to me. My client will be so pleased!

Sincerely,

Nicole B. "
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
comparing two email fields The guy upstairs Javascript 2 11-19-2006 04:10 PM
(CGI-Target)Could not connect to CGI-Proxy John Smith Java 0 05-15-2006 09:21 PM
Python CGI - Accepting Input, Invoking Another Process, Ending CGI LarsenMTL Python 4 11-04-2004 05:59 PM
Calling cgi from cgi thru 'system' function. Different behaviour on browser v/s cmd line Shailan Perl 2 12-15-2003 04:26 PM
Re: CGI Perl "use CGI" statement fail Jürgen Exner Perl 0 07-31-2003 02:00 PM



Advertisments