Forums
This topic is locked
Forms Question
Posted 17 Apr 2007 06:29:27
1
has voted
17 Apr 2007 06:29:27 Claudine Jalajas posted:
Hi, I am using a form on my site. I have a field that asks for their email address and I'd like a second one that verifies that they entered the email the same the second time. How do I do this??Thanks!
Claudine
Replies
Replied 17 Apr 2007 17:55:18
17 Apr 2007 17:55:18 Alan C replied:
put on a second textfield just like the first but call it something different, so now you will have something like email and email_2 as separate form fields
when these arrive at the script that processes them you can check them with a string compare in php, something like
<pre id=code><font face=courier size=2 id=code> if(strcmp($email, $email_2)!=0) {action if not equal}</font id=code></pre id=code>
the function strcmp() returns zero if the strings are exactly equal
another way to do it would be to put in some javascript on the page that way the input from the form does not get sent until the email addresses are the same - you can also check it for being a 'valid' email address too - more javascript though. If you do a search for something like javascript form field validation you will get lots to look at an choose from
when these arrive at the script that processes them you can check them with a string compare in php, something like
<pre id=code><font face=courier size=2 id=code> if(strcmp($email, $email_2)!=0) {action if not equal}</font id=code></pre id=code>
the function strcmp() returns zero if the strings are exactly equal
another way to do it would be to put in some javascript on the page that way the input from the form does not get sent until the email addresses are the same - you can also check it for being a 'valid' email address too - more javascript though. If you do a search for something like javascript form field validation you will get lots to look at an choose from
Replied 25 Apr 2007 12:44:08
25 Apr 2007 12:44:08 satheesh Dominic replied:
<b><center>
Have a look at this Page.... Use what ever you feel like good
</center></b>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?")>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="" {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
<b>
if(document.myForm.email1.value != document.myForm.email2.value )
{
alert("Email Id is not Matching !"
}
</b>
}
//-->
</script>
<style type="text/css">
<!--
.hean {
font-family: "Trebuchet MS", tahoma, arial;
font-size: 11px;
font-weight: bold;
color: #339900;
text-align: left;
}
.bor{border:#009900 solid 1px; margin-top:15px;}
-->
</style>
</HEAD>
<BODY>
<form action="" method="post" name="myForm" onSubmit="MM_validateForm('email1','','RisEmail','email2','','RisEmail');return document.MM_returnValue">
<div>
<span class="hean">
Email ID:
<input name="email1" type="text" class="bor" />
</span>
<br>
<span class="hean">Confirm Email ID:
<input name="email2" type="text" class="bor" />
</span>
<p>
<input type="submit" value="submit" name="go" />
</p>
</div>
</form>
</BODY>
</HTML>
Edited by - satheeshkd on 25 Apr 2007 12:54:50
Edited by - satheeshkd on 26 Apr 2007 07:13:24
Have a look at this Page.... Use what ever you feel like good
</center></b>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?")>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="" {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
<b>
if(document.myForm.email1.value != document.myForm.email2.value )
{
alert("Email Id is not Matching !"
}
</b>
}
//-->
</script>
<style type="text/css">
<!--
.hean {
font-family: "Trebuchet MS", tahoma, arial;
font-size: 11px;
font-weight: bold;
color: #339900;
text-align: left;
}
.bor{border:#009900 solid 1px; margin-top:15px;}
-->
</style>
</HEAD>
<BODY>
<form action="" method="post" name="myForm" onSubmit="MM_validateForm('email1','','RisEmail','email2','','RisEmail');return document.MM_returnValue">
<div>
<span class="hean">
Email ID:
<input name="email1" type="text" class="bor" />
</span>
<br>
<span class="hean">Confirm Email ID:
<input name="email2" type="text" class="bor" />
</span>
<p>
<input type="submit" value="submit" name="go" />
</p>
</div>
</form>
</BODY>
</HTML>
Edited by - satheeshkd on 25 Apr 2007 12:54:50
Edited by - satheeshkd on 26 Apr 2007 07:13:24