Reputation: 63
I have an issue with the validating and further processing Captcha on my form. I would like to confirm the answer is correct then send out the email and send the user to the thank you page otherwise take it to the error page if the user failed to input the proper response to the Captcha. I am capturing the captcha code on a hidden input field on the form. Even after putting in the correct code, it still redirects me to the error.html page I have set up.
See code below I use the 'captcha_code', where I am trying to obtain the value of true/false. Once the answer is either true or false based on that it'll continue the IF statement of either sending an email or taking it to the Thank-You page.
(If there is any code I am missing to post, please do let me know I'll have that code posted up immediately.)
PHP Code: (Updated Code Post Comments Below) *Still being directed to the Error page even if the captcha is correct.
<?php
if ($_POST["submit"]) {
$companyName = $_POST['tscpCompanyName'];
$businessType = $_POST['tscpBusinessType'];
$yearsBusiness = $_POST['tscpYears'];
$numberOfUnits = $_POST['tscpNumberOfUnits'];
$firstName = $_POST['tscpFirstName'];
$lastName = $_POST['tscpLastName'];
$email = $_POST['tscpEmail'];
$number = $_POST['tscpNumber'];
$vals = $_POST['vals'];
$human = intval($_POST['captcha_code']);
$from = "From:[email protected]";
$to = "[email protected]";
$subject = 'Custom Package Request';
$body ="Company Name: $companyName\n\n Business Type: $businessType\n\n Years In Business: $yearsBusiness\n\n First Name: $firstName\n\n Last Name: $lastName\n\n Email: $email\n\n Number: $number\n\n Services: $vals\n\n";
if (!isset($_SESSION)) session_start();
if ($_POST['captcha_code'] == $_SESSION['code']) {
echo 'true';
} else {
echo 'false';
}
//Check if simple anti-bot test is correct
if ($human !== false) {
$errHuman = 'Your anti-spam is incorrect';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) {
header("Location: /thank-you/mortgage-lending.html");
} else {
header("Location: /error.html");
}
}
else {
header("Location: /error.html");
}
}?>
Upvotes: 0
Views: 804
Reputation: 63
I have figured out the solution to the problem. I first and foremost updated the IF statement that would mail out and redirect me to correct page. I also made sure to updated my $POST & session_start().
Here is the PHP Code:
<?php
if (!isset($_SESSION)) session_start();
if ($_POST["submit"])
{
$companyName = $_POST['tscpCompanyName'];
$businessType = $_POST['tscpBusinessType'];
$yearsBusiness = $_POST['tscpYears'];
$numberOfUnits = $_POST['tscpNumberOfUnits'];
$firstName = $_POST['tscpFirstName'];
$lastName = $_POST['tscpLastName'];
$email = $_POST['tscpEmail'];
$number = $_POST['tscpNumber'];
$vals = $_POST['vals'];
$human = intval($_POST['captcha_code']);
$captchaError= FALSE;
$from = "From:[email protected]";
$to = "[email protected]";
$subject = 'Custom Package Request';
$body ="Company Name: $companyName\n\n Business Type: $businessType\n\n Years In Business: $yearsBusiness\n\n First Name: $firstName\n\n Last Name: $lastName\n\n Email: $email\n\n Number: $number\n\n Services: $vals\n\n";
if ($_POST['captcha_code'] != $_SESSION['code'])
{
$captchaError = TRUE;
$errHuman = 'Your anti-spam is incorrect';
}
if (!$errName && !$errEmail && !$errMessage && !$captchaError) {
if (mail ($to, $subject, $body, $from)) {
header("Location: /thank-you/mortgage-lending.html");
} else {
header("Location: /error.html");
}
}
else {
header("Location: /error.html");
}
}?>
Upvotes: 0
Reputation: 23958
You are posting the form with post. So, use $_POST
for captcha, not $_GET
Upvotes: 2