Добавление капчи в форму не работает правильно

Я пытаюсь добавить капчу в эту форму, проверьте ссылку, если хотите.

Это ссылка от Stackoverflow

Но я не могу заставить его работать правильно, когда я ввожу код ошибки, ничего не происходит, и я все еще получаю почту.

<?php
session_start();
$cap = 'notEq';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST['captcha'] == $_SESSION['cap_code']) {
// Captcha verification is Correct. Do something here!
$cap = 'Eq';
} else {
// Captcha verification is wrong. Take other action
$cap = '';
}$to = "exmaple@mail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$ip = $_POST['ip'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . " " . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.

}

?>

И здесь ниже капча и кнопка отправки.

    <!-- Captcha -->
<input type="text" name="captcha" id="captcha" maxlength="6" size="6"/><!-- Submit Button -->
<input type="submit" id="captcha" name="captcha" value="Submit">

Так что я здесь делаю не так?

Спасибо за любую помощь.

0

Решение

Оба поля ввода имеют одинаковое имя, поэтому, скорее всего, содержимое текстового поля перезаписывается значением кнопки отправки.

Измените имя кнопки отправки.

<input type="text" name="captcha" id="captcha" maxlength="6" size="6"/>

<!-- Submit Button -->
<input type="submit" id="captchaBut" name="captchaBut" value="Submit">
0

Другие решения

Других решений пока нет …