Just wondering if someone can help with this captcha code I found on the internet.
After a few attempts I just cant work out how to add the Checks verificaton Code into the Form code - mailer.php.
Help is much appreciated.
Code:
<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('Please Enter the following details:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
FORM CODE
Code:
<form action="mailer.php" method="post" name="form1" id="form1" onsubmit="MM_validateForm('email_from','','RisEmail','subject','','R','verif_box','','R','message','','R');return document.MM_returnValue">
<table>
<tbody>
<tr>
<td>Full Name</td>
<td><input name="FullName" type="text" value="<?php echo $_GET['fullname'];?>" /></td>
</tr>
<tr>
<td>Email</td>
<td><input name="email_from" type="text" value="<?php echo $_GET['email_from'];?>" /></td>
</tr>
<tr>
<td>Comments</td>
<td><textarea rows="4" cols="45" name="Comments" value="<?php echo $_GET['comments'];?>"></textarea></td>
</tr>
<tr>
<td>Verify Code</td>
<td><input name="verif_box" type="text" id="verif_box" style="width: 38px;"/> <img src="verificationimage.php?<?php echo rand(0,9999);?>" alt="verification image, type it in the box" width="50" height="24" /><br />
<!-- if the variable "wrong_code" is sent from previous page then display the error field -->
<?php if(isset($_GET['wrong_code'])){?>
<div style="border:1px solid #990000; background-color:#D70000; color:#FFFFFF; padding:4px; padding-left:6px;width:295px;">Wrong verification code</div><br />
<?php ;}?>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Send" class="buttonb" /> <input type="reset" value="Clear" class="buttonb" /></td>
</tr>
</tbody>
</table>
Checks verificaton Code
Code:
// 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("jason@frogger.com.au", 'TheWebHelp.com Form: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$message, "From: $from");
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
} else if(isset($message) and $message!=""){
// if verification code was incorrect then return to contact page and show error
header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
exit;
} else {
echo "no variables received, this page cannot be accessed directly";
exit;
}
?>
Below code I think should be added after else above.
Form code - mailer.php
Code:
// email for send submitted forms //////////////////////////////////////////
// if empty, use value from form ('send_to' field)
$send_to = "email@domain.,com";
// set $send_cc address if you need copy of mail to other addresses
// for example: $send_cc = array('friend1@ccc.cc', 'friend2@ccc.cc');
//
$send_cc = array();
// Subject. if empty, use value from form ('subject' field)
$subject = "Form";
// Allowed Referres. Should be empty or list of domains
$referrers = array();
// Attachments
$attachment_enabled = 0;
////// Database - write CSV file with data of submitted forms //////////////
$database_enabled = 0;
$database_file = 'workshop.csv';
// Fields to collect
// $database_fields = '*' - mean all fields, as in form
// $database_fields = array('from', 'subject') - only 'from', 'subject' fields
$database_fields = '*';
////// Redirect user after submitting form
$redirect_url = 'thankyou.php';
////// Auto-Responder
////// You can substitute any of form fields in response by using
////// %field_name% in response text.
//////
$autoresponder_enabled = 1;
$autoresponder_from = $send_to;
$autoresponder_subject = "%subject%";
$autoresponder_message = <<<MSG
_________________________________________________________________
Hi,
Thank you for submitting your inquiry.
If you have any further inquiries please don't hesitate to contact us
_________________________________________________________________
MSG;
/***************************************************************************/
function do_formmail(){
global $autoresponder_enabled, $database_enabled;
$form = get_form_data();
$errors = check_form($form);
if ($errors) {
display_errors($errors);
return;
}
send_mail($form);
if ($autoresponder_enabled)
auto_respond($form);
if ($database_enabled)
save_form($form);
redirect();
}
function redirect(){
global $redirect_url;
header("Location: $redirect_url");
exit();
}
function save_form($vars){
global $database_file, $database_fields;
$f = fopen($database_file, 'a');
if (!$f){
die("Cannot open db file for save");
}
foreach ($vars as $k=>$v) {
$vars[$k] = str_replace(array("|", "\r","\n"), array('_',' ',' '), $v);
}
if (is_array($database_fields)) {
$vars_orig = $vars;
$vars = array();
foreach ($database_fields as $k)
$vars[$k] = $vars_orig[$k];
}
$str = join('|', $vars);
fwrite($f, $str."\n");
fclose($f);
}
More code after follows this. Didnt think you need it.