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

B

bateman5

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!
 
B

Brian Genisio

bateman5 said:
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
 
R

Randy Webb

Brian said:
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
(e-mail address removed)
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.
 
B

bateman5

Hi Brian,

My CGI script already confirms that the format is in email syntex
([email protected]). 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!
 
B

Brian Genisio

bateman5 said:
Hi Brian,

My CGI script already confirms that the format is in email syntex
([email protected]). 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
 
B

bateman5

Robert said:
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/clientquest/clientquesta.html

NB
 
B

bateman5

Brian Genisio said:
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/clientquest/clientquesta.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
 
B

Brian Genisio

bateman5 said:
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/clientquest/clientquesta.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;
}
 
R

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/clientquest/clientquesta.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>
 
B

bateman5

Brian Genisio said:
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. ":)
 
B

Brian Genisio

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 am glad it helped. I once used a software license for a library
that was called "BeerWare", where it said (paraphrasing):

"You may use this software, free of charge, for whatever reason, be it
commercial, educational or personal use. If you are ever in the greater
Toronto area, you must buy me a beer."

I really liked that license :)
Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top