...

View Full Version : comparing and validating two fields?



sakib000
03-05-2008, 08:00 PM
Hello friends i m not familiar with php. I can do most of the thing with js but need little help in php. I have a form where user need to re-enter email address and password, i need a php to compare if these inputs are same or not?

Here is the form html

<form id="form1" method="post" action="">
<table width="500" border="0" cellspacing="0" cellpadding="4">
<tr>
<td width="161">Email</td>
<td width="323"><label>
<input type="text" name="email" id="email" />
</label></td>
</tr>
<tr>
<td>Re-Enter Email</td>
<td><label>
<input type="text" name="email2" id="email2" />
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Password</td>
<td><label>
<input name="password" type="password" id="password" size="6" maxlength="12" />
</label></td>
</tr>
<tr>
<td>Re-enter password</td>
<td>
<input name="password2" type="password" id="password2" size="6" maxlength="12" /> </td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Select Plan</td>
<td><select class="element select medium" id="select" name="product">
<option value="1" selected="selected">--Please select--</option>
<option value="Silver Plan - 129.95 USD" >Silver Plan - 129.95 USD</option>
<option value="Gold Plan - 299.95 USD" >Gold Plan - 299.95 USD</option>
<option value="Platinum Plan - 499.95 USD" >Platinum Plan - 499.95 USD</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<label><br />
</label>
<br/>
</form>

How can i do this in my processmail.php

danielwarner
03-05-2008, 08:14 PM
<?php

if(($_POST["email"] == $_POST["email2"]) && ($_POST["password"]==$_POST["password2"])){

//If all fields are valid
header('Location:success.html');

}
else {

//If they are not valid
header('Location:failed.html');

}

?>

Stick that in a .php document and refer to it in your forms action.

sakib000
03-05-2008, 08:18 PM
how to show a error message instead of failed.html?

cheat
03-06-2008, 04:48 AM
replace.

header('Location:failed.html');


with

echo"Error Message";

sakib000
03-06-2008, 06:02 PM
thanks for helping me :) guys. here is my basic sendmail.php


<?php
$from = 'test@testing.threadpunk.com';
$to = 'sakib.live@gmail.com';
$subject = "Product order at angross.com";
$plan = $_POST['product'];
$extrapages = $_POST['additional'];
$purpose = $_POST['mainpurpose'];
$visitordetails = $_POST['visitorsdetails'];
$youlike = $_POST['sitesyoulike'];
$dontlike = $_POST['sitesyoudontlike'];
$colortheme = $_POST['colorguides'];
$adddetails = $_POST['details'];
$logopref = $_POST['logo'];
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$comname = $_POST['companyname'];
$mailadd1 = $_POST['email1'];
$mailadd2 = $_POST['email2'];
$pass1 = $_POST['password'];
$pass2 = $_POST['password2'];
$phonenumber = $_POST['phone'];
$straddress = $_POST['streetaddress'];
$cityname = $_POST['city'];
$statename = $_POST['state'];
$zip = $_POST['postal'];
$name = $_POST['country'];
$howfind = $_POST['howfindus'];

foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}

mail("$to", "$subject", "$plan \n $extrapages \n $purpose \n $visitordetails \n $youlike \n $dontlike \n $sitesyoudontlike \n $colortheme \n $adddetails \n $logopref \n $fname \n $lname \n $comname \n $mailadd1 \n $mailadd2 \n $pass1 \n $pass2 \n $phonenumber \n $straddress \n $cityname \n $statename \n $zip \n $name \n $howfind \n $check_msg","From:$from");

?>

Can someone please configure it to check whether two email fields and two password fields are same or not. if OK script just send a mail, if not OK script just display error message that email fields are not same or password fields are not same.

one more thing, mail client inbox is showing 'from' correctly but send-by is hostgator.com. I don't even know this little thing :confused:

Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum