I am trying to add ReCaptcha into a mail form that I created which is intended for sharing content,
but for some reason the captcha is not being validated when I hit "submit", meaning that even if you enter a wrong text in the captcha, the form will still send the email.
I am using joomla 2.5.8, the recaptcha plugin is enabled (although I don't think it is being intialized since I added the recaptchalib.php myself and I am including the ref to the publickey and privatekey inside the mail form code).
Any help would be very much appreciated!
Thank you!!
here is the code:
<?php require_once('recaptchalib.php'); ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript">
function validateEmail($email)
{
var emailReg = /^([\w-\.]+#([\w-]+\.)+[\w-]{2,4})?$/;
if( !emailReg.test( $email ) )
{
return false;
}
else
{
return true;
}
}
function validateForm()
{
var form = document.mailForm;
if (form.recipient.value == "" || validateEmail(form.recipient.value)==false)
{
alert("bad email");
return false;
}
if (form.subject.value == "")
{
alert("please enter subject");
return false;
}
if (form.content.value == "")
{
alert("please enter massage");
return false;
}
<?php
$privatekey = "privatekey";
$resp = recaptcha_check_answer($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]); ?>
if (!$resp->is_valid)
{
alert("try again");
return false;
}
return true;
}
</script>
<?php
if($this->success=='1')
{
echo JText::_('MAIL_SEND_SUCCESSFULLY');
}
elseif($this->success=='0')
{
echo JText::_('MAIL_SEND_FAILED');
}
?>
<div id="SendMail">
<h2>send mail</h2>
<form action="index.php" name="mailForm" method="post" onsubmit="return validateForm()">
<table>
<tr>
<td><label><?php echo JText::_('MAIL_SEND_TO'); ?>:</label></td>
<td><input type="text" name="recipient" size="25" value=""/></td>
</tr>
<tr>
<td><label><?php echo JText::_('MAIL_SUBJECT'); ?>:</label></td>
<td><input type="text" name="subject" size="25" value=""/></td>
</tr>
<tr>
<td><label><?php echo JText::_('MAIL_MESSAGE'); ?>:</label></td>
<td>
<textarea name="content" rows="10" cols="40"></textarea>
<br/><?php echo JText::_('MAIL_DESC'); ?>
</td>
<tr>
<td><?php $publickey = "public key"; ?></td>
<td><?php echo recaptcha_get_html($publickey);?></td>
</tr>
</table>
<p>
<input type="hidden" name="controller" value="mail" />
<input type="hidden" name="task" value="sendMail" />
<div class="button-mail">
<input style="width: 50px;height: 25px;" type="submit" name="submit" value="<?php echo JText::_('SEND'); ?>"/>
<a href="javascript: void window.close()" title="Close Window"><span style="color: #444;
border: #D5D5D5 1px solid; padding: 4px; width: 50px;height: 25px;"><?php echo JText::_('CLOSE'); ?></span></a>
</div>
</p>
</form>
</div>
You have error in the code. Please look this lne
if (!$resp->is_valid)
{
alert("try again");
return false;
}
Where $resp->is_valid is the PHP but executed as JS.
Correct code would be
if (!<php (int)$resp->is_valid;?>)
{
alert("try again");
return false;
}
But it will not work anyway because of 2.
You cannot check recaptcha code in Javascript validation. It should be checked server side. Or if you want to check with javascript it should be checked with AJAX request to server. That is because you code
<?php
$privatekey = "privatekey";
$resp = recaptcha_check_answer($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]); ?>
is executed on form load before even user eneter captcha.
Related
Title says it all...I have a contact form that allows four files to be uploaded. If you upload large files, the form actually "forgets" name, phone number, e-mail, etc. At least, I get the error screen telling the user to provide that info, and I don't get the e-mail message.
If I use small files (like, say, a megabyte or less), it works fine, and I get the files, but any more bandwidth and it's like I'm submitting a blank form, even though it goes through the motion of uploading the files (it takes well over a minute before I get the error page).
Here's the source of the form itself, including some PHP:
<?php
ini_set("max_input_time","5");
ini_set("max_execution_time","1");
ini_set("upload_max_filesize","2048M");
ini_set("post_max_size","2048M");
?>
<html>
<head>
<script language="Javascript">
function formValidate() {
// Did the user include a name?
var userName=document.forms["contactRich"]["cName"].value;
if (userName=="" || userName==null) {
alert("Please provide your name.");
return false;
}
// Did the user include a phone number and area code?
var phoneNumber=document.forms["contactRich"]["cNumber"].value;
var areaCode=document.forms["contactRich"]["cAreaCode"].value;
if (phoneNumber=="" || phoneNumber==null || areaCode=="" || areaCode==null) {
alert("Please include your phone number with the area code.");
return false;
}
// Did the user provide a valid e-mail address?
var emailAddress=document.forms["contactRich"]["cEmail"].value;
var atCount=emailAddress.split("#").length-1;
var lastAt=emailAddress.lastIndexOf("#");
var isDot=emailAddress.lastIndexOf(".");
var filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(emailAddress) || emailAddress=="" || emailAddress==null || emailAddress.length<5 || lastAt <0 || isDot<0 || isDot<lastAt || atCount!=1) {
alert("Please provide a valid e-mail address.");
return false;
}
// Did the user select a service?
if (document.forms["contactRich"]["cTopic"].value=="null") {
alert("Please tell us what you need help with.");
return false;
}
document.getElementById("isValid").value="yes";
return true;
}
</script>
<!-- #BeginEditable "doctitle" -->
<title>Contact Rich</title>
<!-- #EndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.form { font-family: "Franklin Gothic Medium", "Trebuchet MS"; font-size: 13pt}
-->
</style>
</head>
<body bgcolor="#CCCCCC">
<table width="800" border="0" cellspacing="2" cellpadding="2" align="center" bgcolor="#FFFFFF">
<form name="contactRich" id="contactRich" method="post" action="formHandler2.php" enctype="multipart/form-data" onsubmit="return fabFormValidate()">
<table cellpadding="6">
<tr>
<td colspan="2"><h3>Contact</h3></td>
</tr>
<tr>
<td class="form">Your name:</td>
<td><input type="text" name="cName" size="31"></td>
</tr>
<tr>
<td class="form">Your phone number:<br /><span class="footer">(Include area code)</span></td>
<td>(<input type="text" size="3" maxlength="3" name="cAreaCode"/>) <input type="text" id="cNumber" name="cNumber" size="23"></td>
</tr>
<tr>
<td class="form">Your e-mail address:</td>
<td><input type="text" name="cEmail" size="31"></td>
</tr>
<tr>
<td class="form">What can we help you with?</td>
<td><select name="cTopic">
<option value="null">(Please choose:)</option>
<option value="an estimate">Estimate</option>
<option value="bifold doors">Bifold doors</option>
<option value="broken window ropes">Broken window ropes</option>
<option value="door that won't stay shut">My door won't stay shut!</option>
<option value="noisy doors">My door is noisy!</option>
<option value="sticking doors">My door is sticking!</option>
<option value="drywall repairs">Drywall repairs</option>
<option value="garbage disposals">Garbage disposals</option>
<option value="grab bars">Grab bars</option>
<option value="your various services">(other)</option>
</select></td>
</tr>
<tr>
<td class="form">Any additional details?</td>
<td><textarea name="cAdditional" cols="27" rows="4" wrap="soft"></textarea></td>
</tr>
<tr>
<td class="form">You may include up to<br />four pictures:</td>
<td>
<input type="file" name="file_1" id="file_1" /><br />
<input type="file" name="file_2" id="file_2" /><br />
<input type="file" name="file_3" id="file_3" /><br />
<input type="file" name="file_4" id="file_4" /><br />
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Submit" /></td>
</tr>
<tr>
<td colspan="2"><hr /></td>
</tr>
</table>
<input type="hidden" id="isValid" name="isValid" value="no" />
</form>
</table>
<p> </p>
</body>
</html>
Here's the PHP that actually processes the data and tries to send it, via PHPMailer:
<?php
ini_set("max_input_time","5");
ini_set("max_execution_time","1");
ini_set("upload_max_filesize","2048M");
ini_set("post_max_size","2048M");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<?php
$error_exists = false;
$masterEmail = "email#goes.here";
require 'PHPMailer-master/PHPMailerAutoload.php';
include "Form.php";
$name = $_POST['cName'];
$areaCode = $_POST['cAreaCode'];
$phone = $_POST['cNumber'];
$email = $_POST['cEmail'];
$from = "from_address#goes.here";
$topic = "(WEB) ".$_POST['cTopic'];
$additional = $_POST['cAdditional'];
$isValid = $_POST['isValid'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r<br /> <br />";
$body = "Name: ".$name."<br /> <br />";
$body = $body."Phone number: (".$areaCode.") ".$phone."<br /> <br />";
$body = $body."E-mail address: ".$email."<br /> <br />";
$body = $body."Needs help with: ".$topic."<br /> <br />";
if (!empty($additional)) {
$body = $body .$additional;
}
$body .= "\n\nIP address: ".$_SERVER['REMOTE_ADDR']."<br /> <br />";
$body .= "Browser: ".$_SERVER['HTTP_USER_AGENT']."<br /> <br />";
$mail = new PHPMailer();
$mail->addAddress($masterEmail);
$mail->setFrom($email, $from);
$mail->Subject = $subject;
$mail->msgHTML($body);
if (isset($_FILES['file_1'])) {
$mail->addAttachment($_FILES['file_1']['tmp_name'],$_FILES['file_1']['name']);
}
if (isset($_FILES['file_2'])) {
$mail->addAttachment($_FILES['file_2']['tmp_name'],$_FILES['file_2']['name']);
}
if (isset($_FILES['file_3'])) {
$mail->addAttachment($_FILES['file_3']['tmp_name'],$_FILES['file_3']['name']);
}
if (isset($_FILES['file_4'])) {
$mail->addAttachment($_FILES['file_4']['tmp_name'],$_FILES['file_4']['name']);
}
if (empty($name)) {
$errors = "Please provide your name.<br />";
$error_exists = true;
}
if (!ctype_digit($areaCode) || strlen($areaCode) != 3 || strlen($phone) < 7) {
$errors .= "Please provide your phone number, including area code.<br />";
$error_exists = true;
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors .= "Please enter a valid e-mail address.<br />";
$error_exists = true;
}
if (empty($topic)) {
$errors .= "Please tell us what you need help with.<br/>";
$error_exists = true;
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<title>Request for Information</title>
</head>
<body bgcolor="#cccccc">
<?php
$f=new fabForm();
$f->setSubject($subject);
$f->setBody($body);
$f->setEmail($email);
$f->setFrom($from);
?>
<p> </p>
<table align="center" bgcolor="#FFFFFF">
<tr>
<td>
<?php
if ($error_exists) {
echo $errors;
echo " <br />";
echo "<a href='contact.php'>Click here to try again.</a>";
} else {
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</td>
</tr>
</table>
</body>
</html>
Finally, here's the form class I'm using:
<?php
class Form {
private $email;
private $subject;
private $body;
private $from;
private $headers;
// SET methods
public function setEmail($emailAddress) {
$this->email=$emailAddress;
}
public function setSubject($subjectLine) {
$this->subject=$subjectLine;
}
public function setBody($bodyText) {
$this->body=$bodyText;
}
public function setHeaders($sizeHeaders) {
$this->headers=$sizeHeaders;
}
public function setFrom($whoFrom) {
$this->from="From:".$whoFrom."\n".$this->headers;
}
// ACCESSOR METHODS
public function getEmail() {
return $this->email;
}
public function getSubject() {
return $this->subject;
}
public function getBody() {
return $this->body;
}
public function getHeaders() {
return $this->headers;
}
public function getFrom() {
return $this->from;
}
public function sendMail($sendHere) {
if (mail(
$sendHere,
stripslashes($this->getSubject()),
stripslashes($this->getBody()),
$this->getFrom()
)
)
echo("<p>Your request has been sent.</P>");
else
echo("<p>Due to technical difficulties, your request could not be delivered.</p>");
}
}
?>
I can post the PHPMailer source files, but that's practically a whole software package...
But what would cause the form's data to literally be forgotten?? How could I prevent it??? (And limiting file size is not a feasible option.) If it helps, the host is 1and1.com.
when the file is bigger than post_max_size the "POST datas" are erased by PHP
a solution would be to send the file by AJAX before to submit the form. look here to know how to do this :
Upload image with JavaScript from another server via AJAX
I want go to another page if the condition allowed. But when i submit the button it just like refresh the page. it doesn't direct to another page.
I have already read another question remain same but did not change.
Here is my code :
<?php
session_start();
if(isset($_POST['login']))
{
$nik = $_POST['nik'];
$pswd = $_POST['pswd'];
if ((empty($nik)) or (empty($pswd)))
echo "Data masih ada yang kosong<br/><br/>";
else
{
include("sss_connection.php");
$connection = mysql_connect($server,$user,$pass);
$db = mysql_select_db("skripsi");
if(!$connection)
{
echo "Database belum terkoneksi<br/><br/>";}
elseif(!$db)
{
echo "Database Tidak Ada<br/><br/>";}
else
{
$sql1 = "select count(*) as cek,kd_jabatan from datakaryawan where nik='".$nik."' and password='".$pswd."'";
//$exec = mysql_query($sql1);
$ambil_data = mysql_query($sql1);
if ($data = mysql_fetch_array($ambil_data))
{
$cek = $data["cek"];
$jabatan = $data["kd_jabatan"];
}
if(($jabatan) == 0)
{
echo "Anda gagal Login, NIK / Password salah<br/><br/>";
}
else
{
header("Location: sss_header.php");
}
}
}
}?>
And here is my html code :
<html>
<head>
<title>Login</title>
</head>
<body>
<form method="post">
<div style="float:left;margin-left:35%;margin-top:5%;">
<center><strong><font size="6">Login</font></strong></center>
</br></br>
<table style="float:left;margin-left:5%;">
<tr>
<td width=84>NIK</td>
<td width=10>:</td>
<td width=30><input type="text" name="nik" size=30 onkeypress="return isNumber(event)" style="width: 217px" autofocus></td>
</tr>
<tr>
<td width=70>Password</td>
<td width=10>:</td>
<td width=30><input type="password" name="pswd" size=30 style="width: 217px"></td>
</tr>
</table><blockquote><blockquote><br/><br/>
<input type="submit" value="Login" name="login" style="float:left; margin-left:45px; margin-top:12px;">
<input type="submit" value="Daftar" name="daftar" style="float:left; margin-left:26px; margin-top:12px;">
<input type="reset" value="Clear" style="float:left; margin-left:26px; margin-top:12px;">
</form>
</div>
<div style="float:left;margin-left:35%;margin-top:5%;">
</div>
</body>
</html>
you have to specified the action attribute on your form tag, should be like this:
<form method="post" action="anotherplace.php">
I am trying to change the password from the user logged in. On the page it says the password was changed, but it does not change, not on the database and not at all. I have trying logging in with the new password, but just the old one remains to login. I did refreshed the page and everything. I am trying this for a couple of days and I wonder if someone would kindly spot my error. Tonight I thought it could be because the password is encrypted with md5 on the database. How would I proceed as I already tried a few things and do not work.
error_reporting(E_ALL); ini_set("display_errors","On");
<?php include "includes/connection.php" ?>
<?php
session_start();
if(#$_REQUEST["Submit"]=="Update")
{
$sql="update users set password ='$_REQUEST[newpassword]' where user='$_SESSION[myusername]'";
if (!mysql_query($sql)) die('err: PROBLEM IN QUERY: '.mysql_error());
header("Location:changpass.php?msg=updated");
}
else
die('err: PROBLEM IN REQUEST');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Change password</TITLE>
<script language="javascript" type="text/javascript">
function validate()
{
var formName=document.frm;
if(formName.newpassword.value == "")
{
document.getElementById("newpassword_label").innerHTML='Please Enter New Password';
formName.newpassword.focus();
return false;
}
else
{
document.getElementById("newpassword_label").innerHTML='';
}
if(formName.cpassword.value == "")
{
document.getElementById("cpassword_label").innerHTML='Enter ConfirmPassword';
formName.cpassword.focus();
return false;
}
else
{
document.getElementById("cpassword_label").innerHTML='';
}
if(formName.newpassword.value != formName.cpassword.value)
{
document.getElementById("cpassword_label").innerHTML='Passwords Missmatch';
formName.cpassword.focus()
return false;
}
else
{
document.getElementById("cpassword_label").innerHTML='';
}
}
</script>
<style type="text/css">
<!--
.style1 {font-weight: bold}
.style7 {
color: yellow;
font-size: 24px;
}
.style9 {
color: #FF6666;
font-weight: bold;
}
.style12 {
color: #666666;
font-weight: bold;
}
.style14 {color: #CC0033; font-weight: bold; }
-->
</style>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
</HEAD>
<BODY>
<form action="changpass.php" method="post" name="frm" id="frm" onSubmit="return validate();">
<table width="47%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" align="center"></td>
</tr>
<tr bgcolor="#666666">
<td colspan="2"><span class="style7">Change Password</span></td>
</tr>
<?php if(isset($_REQUEST['msg']) && $_REQUEST['msg'] == 'updated') { ?>
<tr bgcolor="#666666">
<td colspan="2"><span class="style7">Password has been changed successfully.</span></td>
</tr>
<?php } ?>
<tr>
<td bgcolor="#CCCCCC"><span class="style14">New Password:</span></td>
<td bgcolor="#CCCCCC"><input type="password" name="newpassword" id="newpassword" size="20" autocomplete="off"/> <label id="newpassword_label"
class="level_msg"></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"><span class="style14">Confirm Password:</span></td>
<td bgcolor="#CCCCCC"><input type="password" name="cpassword" id="cpassword" size="20" autocomplete="off"> <label id="cpassword_label"
class="level_msg"></td>
</tr><tr bgcolor="#666666"><td colspan="2" align="center"><input type="submit" name="Submit" value="Update" /></td>
</tr></table>Home</form></BODY></HTML>`
I enhanced your code:
<?php
if ($_REQUEST['Submit'] == "Update")
{
$sql = "UPDATE `users` SET `password`='".$_REQUEST['newpassword']."' WHERE `user`='".$_SESSION['myusername']."'";
mysql_query($sql);
header("Location: changpass.php?msg=updated");
exit;
}
?>
To use this code make sure following:
1) You are having correct Submit button, example is following:
<input type="submit" name="Submit" value="Update" />
2) You are having correct password field, example is following:
<input type="password" name="newpassword" value="" />
3) Session has to be set under key myusername
4) Make sure your table fields and names are okay. Do more debugging.
If this still won't solve, add form code for further investigation.
EDIT
Here is interpretation of this code with for some basic debugging purposes that might help:
<?php
if (isset($_REQUEST['Submit']) && $_REQUEST['Submit'] == "Update")
{
if (!isset($_SESSION['myusername'])) trigger_error("DEBUG: SESSION VARIABLE IS NOT SET");
if (!isset($_REQUEST['newpassword']) || empty($_REQUEST['newpassword'])) trigger_error("DEBUG: NEW PASSWORD IS NOT GIVEN");
$sql = "UPDATE `users` SET `password`='".mysql_real_escape_string($_REQUEST['newpassword'])."' WHERE `user`='".mysql_real_escape_string($_SESSION['myusername'])."'";
$qw = mysql_query($sql);
if (!$qw) trigger_error("DEBUG: MYSQL RESPONDED WITH ERROR - ".mysql_error());
header("Location: changpass.php?msg=updated");
exit;
}
?>
UPDATE: Debugging step #1
Change a code in your php file to this and tell us if any error messages show up.
if(#$_REQUEST["Submit"]=="Update")
{
$sql="update users set password ='$_REQUEST[newpassword]' where user='$_SESSION[myusername]'";
if (!mysql_query($sql)) die('err: PROBLEM IN QUERY: '.mysql_error());
header("Location:changpass.php?msg=updated");
}
else
die('err: PROBLEM IN REQUEST');
This question already has an answer here:
Closed 11 years ago.
Currently on my website I have a form in which once it is submitted, you're taken to a blank screen with the appreciation message.
Instead of moving to a new page, I wish to keep my users on the same page. How might I go about creating a popup and keeping the user within the same page?
You can use javascript validation or HTML5.
If you don't want these ways you can just open a popup window and set your form's target to it. Like this :
<form method="post" action="anything.php" onsubmit="window.open('','my_form_target', 'width=300,height=200', true); this.target='my_form_target';" >
...
try this for validation
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$name = $_POST['uname'];
$email = $_POST['email'];
$valid_arr = array();
$error_arr = array();
if($name == ''){
$error_arr['name'] = 'Required';
}
else if(!preg_match('/^[a-zA-A]+$/',$name)){
$error_arr['name'] = 'Please put correct value';
}
else{
$valid_arr['name'] = $name;
}
if($email == ''){
$error_arr['email'] = 'Required';
}
else if(!preg_match('/^[a-zA-Z0-9._-]+#[a-zA-Z0-9._-]+\.([a-zA-Z]{2,4})$/',$email)){
$error_arr['email'] = 'Exm.- john#gmail.com';
}
else{
$valid_arr['email'] = $email;
}
if(count($error_arr) == 0){
header('location: success.php');
}
else{
echo 'Error in Loading';
}
}
?>
<html>
<head>
</head>
<body>
<form action="<?php $_SERVER['PHP_SELF'];?>" method="POST">
<table>
<tr>
<td><label>User Name :</label></td>
<td><input type="text" name="uname" value="<?php echo $valid_arr['name'];?>"/></td>
<td class="error"><?php echo $error_arr['name'];?></td>
</tr>
<tr>
<td><label>Email :</label></td>
<td><input type="text" name="email" value="<?php echo $valid_arr['email'];?>"/></td>
<td class="error"><?php echo $error_arr['email'];?></td>
</tr>
<tr>
<td><input type="submit" name="save" value="Submit"/></td>
</tr>
</table>
</form>
</body>
</html>
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.