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

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt;
&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt; New Document &lt;/TITLE&gt;
&lt;META NAME="Generator" CONTENT="EditPlus"&gt;
&lt;META NAME="Author" CONTENT=""&gt;
&lt;META NAME="Keywords" CONTENT=""&gt;
&lt;META NAME="Description" CONTENT=""&gt;
&lt;script type="text/JavaScript"&gt;
&lt;!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?")&gt;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&lt;d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i&lt;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&lt;(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&lt;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&lt;min || max&lt;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>
}
//--&gt;
&lt;/script&gt;
&lt;style type="text/css"&gt;
&lt;!--
.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;}
--&gt;
&lt;/style&gt;
&lt;/HEAD&gt;

&lt;BODY&gt;
&lt;form action="" method="post" name="myForm" onSubmit="MM_validateForm('email1','','RisEmail','email2','','RisEmail');return document.MM_returnValue"&gt;
&lt;div&gt;
&lt;span class="hean"&gt;
Email ID:
&lt;input name="email1" type="text" class="bor" /&gt;
&lt;/span&gt;
&lt;br&gt;
&lt;span class="hean"&gt;Confirm Email ID:
&lt;input name="email2" type="text" class="bor" /&gt;
&lt;/span&gt;
&lt;p&gt;
&lt;input type="submit" value="submit" name="go" /&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;



Edited by - satheeshkd on 25 Apr 2007 12:54:50

Edited by - satheeshkd on 26 Apr 2007 07:13:24

Reply to this topic