Okay, I am a little confused because this code was working and for some reason has stopped. Not sure when it stopped working, but someone on this site created it for me and it was perfect when it worked. The person combined my mailer.php, redirect pages, and html code all in one awesome page. The successful page submitted works, but the incorrect verification code error spontaneously stopped working (?).
Here is the code:
<?php
$state = 0;
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon']){
// if verification code was correct send the message and show this page
mail("myemail@hotmail.com", 'Website Inquiry '.$subject, "\n\n".'Name: '.$name."\n\n".'Company: '.$company."\n\n".'Phone Number: '.$phone."\n\n".'Contact Me By: '.$ContactMethod."\n\n".'City: '.$city."\n\n".'I am Interested In: '.$InterestedIn."\n\n".'Comments: '.$comments."\n\n".$from."\n\n".$_SERVER['REMOTE_ADDR'], "From: $email");
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
$state = 2;
} else if(isset($message) and $message!=""){
// if verification code was incorrect then return to contact page and show error
$state = 1;
}
if ($state == 0) { ?>
<form action="" method="post" name="form1" id="form1" onsubmit="MM_validateForm('email','','RisEmail','name','','R','verif_box','','R','comments','','R');return document.MM_returnValue">
Contact Form
Please complete the form below to have someone from our sales team contact you
<p><strong>Tell us what you're interested in:</strong></p>
<dl>
<dd>
<input type="radio" name="InterestedIn" value="BIBS<?php echo $_GET['InterestedIn'];?>"> Blow-In-Blanket System
<input type="radio" name="InterestedIn" value="Spray Foam<?php echo $_GET['InterestedIn'];?>"> Soya Spray Foam
<input type="radio" name="InterestedIn" value="Attic Insulation<?php echo $_GET['InterestedIn'];?>"> Attic Insulation
<input type="radio" name="InterestedIn" value="Not Sure<?php echo $_GET['InterestedIn'];?>" checked="checked"> Not Sure</dd>
</dl>
<p><strong>Enter additional comments* in the space provided below:</strong></p>
<dl>
<dd><textarea name="comments" cols="50" rows="5" border="0" id="comments"><?php echo $_GET['comments'];?></textarea></dd>
</dl>
<p><strong>Tell us how to get in touch with you:</strong></p>
<dl>
<dd>
<table>
<tr>
<td>Name*</td>
<td>
<input type="text" size="40" maxlength="256" name="name" id="name" value="<?php echo $_GET['name'];?>"></td>
</tr>
<tr>
<td>Company</td>
<td>
<input type="text" size="40" maxlength="256" name="company" value="<?php echo $_GET['company'];?>"></td>
</tr>
<tr>
<td>Email*</td>
<td><input type="text" size="40" maxlength="256" name="email" id="email" value="<?php echo $_GET['email'];?>"></td>
</tr>
<tr>
<td>Phone</td>
<td><input type="text" size="40" maxlength="256" name="phone" value="<?php echo $_GET['phone'];?>"></td>
</tr>
<tr>
<td>City</td>
<td><input type="text" size="40" maxlength="256" name="city" value="<?php echo $_GET['city'];?>"></td>
</tr>
</table>
</dd>
</dl>
<p><strong>Best method to get in touch with you:</strong></p>
<dl>
<dd><input type="radio" name="ContactMethod" value="telephone<?php echo $_GET['InterestedIn'];?>" checked="checked"> Phone
<input type="radio" name="ContactMethod" value="email<?php echo $_GET['InterestedIn'];?>"> Email
</dd>
</dl>
-
” alt=”verification image, type it in the box” width=”50″ height=”24″ align=”top” />
Enter Verification Image
<p style="padding-left:60px;"><input type="submit" class="button primary" value="Submit Form" name="submit"/>
<input type="reset" class="button primary" value="Clear Form" name"clear" /></p>
and then at the bottom of the page after the /html tag:
<?php } else if ($state == 1) { ?>
<h3>Error</h3>
<p>Wrong Verification Code Entered - Go back and try again</p>
<?php } else if ($state == 2) { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
and then the rest of the html here… for the successful page submitted and then the closing php tag.
Any ideas why it stopped working? Any way to fix this with in the current code? If not, I need some way to tell the user of the form that they have submitted the wrong verification code. Currently, if you enter the wrong code it just refreshes the current page.
Any help would be greatly appreciated. I am not well versed in php, so please use lamens terms!
Javascript:
<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 == '');
}
//-->
</script>
Verificationimage.php file code:
<?php
// -----------------------------------------
// The Web Help .com
// -----------------------------------------
header('Content-type: image/jpeg');
$width = 50;
$height = 24;
$my_image = imagecreatetruecolor($width, $height);
imagefill($my_image, 0, 0, 0xFFFFFF);
// add noise
for ($c = 0; $c < 40; $c++){
$x = rand(0,$width-1);
$y = rand(0,$height-1);
imagesetpixel($my_image, $x, $y, 0x000000);
}
$x = rand(1,10);
$y = rand(1,10);
$rand_string = rand(1000,9999);
imagestring($my_image, 5, $x, $y, $rand_string, 0x000000);
setcookie('tntcon',(md5($rand_string).'a4xn'));
imagejpeg($my_image);
imagedestroy($my_image);
?>
The verificationimage file was a big missing piece. That is where the cookie is being set. It looks like perhaps one line of code at the top of your script got removed accidentally and thus caused your problem. Unless it just wasn’t copied in. I can’t tell what the html field name of your verification image would be, but at the very top line you should have something like:
$verif_box = $_POST[‘verification_field’];
You are not setting the value for the $verif_box variable, so it will always fail.