E-mail Confirmation in PHP?

Alex

New member
I have a form on my web page that asks for the user's e-mail address and I want to have a text field that asks them to confirm their email. How do I check, in php, to make sure these two values are equal before they click submit and give them a response saying their email addresses did not match if it didn't? Thanks.
 
<html>

<script language="javascript">
function checkEmail()
{
if(document.getElementById('email1').value != document.getElementById('email2').value)
{
alert('Email and confirm email is not same. Please check');
return false;
}
else
{
alert('Both are same');
}
}
</script>

Email: <input type="text" name="email1" value="" id="email1"><br><br>
Confirm Email: <input type="text" name="email2" value="" id="email2"><br><br>
<input type="button" name="subbutt" id="subbutt" value="Submit" onclick="checkEmail();">

</html>
 
<html>

<script language="javascript">
function checkEmail()
{
if(document.getElementById('email1').value != document.getElementById('email2').value)
{
alert('Email and confirm email is not same. Please check');
return false;
}
else
{
alert('Both are same');
}
}
</script>

Email: <input type="text" name="email1" value="" id="email1"><br><br>
Confirm Email: <input type="text" name="email2" value="" id="email2"><br><br>
<input type="button" name="subbutt" id="subbutt" value="Submit" onclick="checkEmail();">

</html>
 
You can't. Sorry. Not without good ol' JavaScript. And here's why.

See, PHP is the server doing all the thinking. And in order for it to do the thinking, you have to tell it to think. Once your computer get the webpage fully loaded, the server is done thinking. Now...JavaScript makes your computer do the thinking. So it can check if to boxes match. Now, here are your options.
1: Make PHP check and see if they match after the user clicks submit.
2. Make Javascript check and see if they match before the user clicks submit.

Or... if you REALLY want PHP to check....

3. Make JavaScript asynchronously call a PHP function or page to check the two emails. Look into AJAX a little bit.

But seriously... just use JavaScript.
 
Back
Top