Forum Moderators: coopster
Here is my form code (where the CAPTCHA is):
<td class="pgtext12BBlue">
<img src="CaptchaSecurityImages.php" />
</td>
<td align="left">
<span class="pgtext10">Enter Security Code (from image on left):</span>
<input id="security_code" name="security_code" size="15" type="text" value=<?php echo $_POST['security_code']?> >
</td>
Here is the form action script:
<?php
$error=0;
$email=$_POST[email];
$phone=$_POST[phone];
$fname=$_POST[firstname];
$lname=$_POST[lastname];
$company=$_POST[company];
$number=$_POST[number];
$security_code=$_POST['security_code'];
if(empty($email)¦¦empty($phone))
{echo "<b>You didn't input either your email or phone number.<br> Please go back and try it again.</b>";
$error=1;
}
elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
{
echo "<b>The e-mail was not valid. <br> Please go back and try it again.</b>";
$error=1;
}
elseif(!eregi("^[0-9-]+([0-9-]+)*[0-9-]+([0-9-]+)*$", $phone))
{
echo "<b>The phone number was not valid. <br> Please go back and try it again.</b>";
$error=1;
}
elseif( $_SESSION['security_code'] == $_POST['security_code'] &&!empty ($_SESSION['security_code']))
{
echo "<b>Anti-spam security code incorrect. Please try again.</b>";
$error=1;
}
The script then proceeds. If there are errors, user is prompted to go back... If no errors, script takes data entry and E-Mails to me.
I realize that this statement where the CAPTCHA validation is is incorrect:
elseif( $_SESSION['security_code'] == $_POST['security_code'] &&!empty ($_SESSION['security_code']))
{
echo "<b>Anti-spam security code incorrect. Please try again.</b>";
$error=1;
}
!= instead of ==, but to no avail. I've tried making the part after == begin with !(2nd half here), but that also didn't work. I want it such that if the CAPTCHA is entered incorrectly, an error message is sent.
Any way to re-write the validation statement so that I get my desired results? Let me know. Thanks.
not sure of php order of ops, but you could try an extra set of parentheses to force it:
elseif(($_SESSION['security_code'] == $_POST['security_code']) &&!empty ($_SESSION['security_code']))