Trying to combine two sets of someone else’s code to put a Captcha on my form
My efforts so far are nearly there
But it not quite working properly for some reason if you don’t fill in the Captcha it goes to the home page
and dose not display the error message.
Below is my form
[code]
First Name * | |
Last name * | |
House name or number * | |
Address | |
Address | |
Address | |
Post code * | |
Phone Number * | |
Email * | |
Interested in | |
Security Code | |
Next the php for the form
[php]<?php ob_start();
$fromemail=“No-Reply <@kensington-sashwindows.co.uk>”; // change here if you want
$toemail="[email protected]"; // change here if you want
$sub=“Online Feedback”; // change here if you want
$success_page_name=“success.html”;
////// do not change in following
if($_SERVER[‘REQUEST_METHOD’]==“POST”)
{
$fieldnm_1=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_1’]));
$fieldnm_2=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_2’]));
$fieldnm_3=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_3’]));
$fieldnm_4=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_4’]));
$fieldnm_5=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_5’]));
$fieldnm_6=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_6’]));
$fieldnm_7=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_7’]));
$fieldnm_8=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_8’]));
$fieldnm_9=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_9’]));
$fieldnm_10=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_10’]));
$contentmsg=stripslashes("
$sub
First Name *: | $fieldnm_1 |
Last name *: | $fieldnm_2 |
House name or number *: | $fieldnm_3 |
Address: | $fieldnm_4 |
Address: | $fieldnm_5 |
Address: | $fieldnm_6 |
Post code *: | $fieldnm_7 |
Phone Number *: | $fieldnm_8 |
Email *: | $fieldnm_9 |
Comments : | $fieldnm_10 |
The code for the Captcha
[php]<?php
session_start();
if( isset($_POST[‘submit’]))
{
if( $_SESSION[‘security_code’] == $_POST[‘security_code’] && !empty($_SESSION[‘security_code’] ) )
{
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
echo ‘Thank you. Your message said "’.$_POST[‘message’].’"’;
unset($_SESSION[‘security_code’]);
}
else
{
// Insert your code for showing an error message here
echo ‘Sorry, you have provided an invalid security code’;
}
} else {
?>[/php]
My efforts so far any ideas why it goes to the home page, many thanks Paul
[php]<?php session_start();
if(($_SESSION[‘security_code’] == $_POST[‘security_code’]) && (!empty($_SESSION[‘security_code’])) ) {
// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
$fromemail=“No-Reply <@kensington-sashwindows.co.uk>”; // change here if you want
$toemail="[email protected]"; // change here if you want
$sub=“Online Feedback”; // change here if you want
$success_page_name=“success.html”;
////// do not change in following
unset($_SESSION['security_code']);
}else { “Sorry, you have provided an invalid security code”;
}
////// do not change in following
if($_SERVER[‘REQUEST_METHOD’]==“POST”){
$fieldnm_1=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_1’]));
$fieldnm_2=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_2’]));
$fieldnm_3=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_3’]));
$fieldnm_4=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_4’]));
$fieldnm_5=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_5’]));
$fieldnm_6=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_6’]));
$fieldnm_7=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_7’]));
$fieldnm_8=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_8’]));
$fieldnm_9=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_9’]));
$fieldnm_10=str_replace ( array("\n"), array("
"),trim($_REQUEST[‘fieldnm_10’]));
$contentmsg=stripslashes("
$sub
First Name *: | $fieldnm_1 |
Last name *: | $fieldnm_2 |
House name or number *: | $fieldnm_3 |
Address: | $fieldnm_4 |
Address: | $fieldnm_5 |
Address: | $fieldnm_6 |
Post code *: | $fieldnm_7 |
Phone Number *: | $fieldnm_8 |
Email *: | $fieldnm_9 |
Comments : | $fieldnm_10 |
////
$headers = "MIME-Version: 1.0
";
$headers .= "Content-type: text/html; charset=iso-8859-1
";
$from=$fromemail;
$headers .= "From: “.$from.”
";
@mail($toemail,$sub,$contentmsg,$headers);
header(“Location:$success_page_name”);
}?>[/php]