联系表单的验证码集成问题

Captcha integration issues to contact form

提问人:dodogitar 提问时间:11/9/2023 最后编辑:dodogitar 更新时间:11/9/2023 访问量:28

问:

我想在我网站的联系部分使用验证码来清除垃圾邮件。当我将找到的验证码添加到联系表单时,消息已发送,但验证码不起作用。如果我关闭联系表单的操作部分,验证码会起作用,邮件不会发送。如果我打开联系表单的操作线,这次它与验证码的操作冲突,验证码不起作用。

联系人 .php 表单代码

<article id="content" style="padding:0px 0px 5px 0px;">
  <header class="module-a" style="padding-left: 10px;">
    <h2>Contact Information</h2>
  </header>
  
</article>
<article id="content" class="cols-b">
  <form  onSubmit="return submitForm();" action="contact-mail-action.php" method="post" class="form-b" name="homefrm1" id="homefrm1">
  <input type="hidden"  name="event" value="start" />
  <fieldset>
  <div class="container">
  <legend>Send us a message</legend>
  <form method="POST" action="">
    <div class="form-group">
      <label for="adsoyad">Name-Surname</label>
      <input type="text" class="form-control" name="adsoyad" id="adsoyad" required>
    </div>
    <div class="form-group">
      <label for="email">E-Mail</label>
      <input type="email" class="form-control" name="email" id="email" required>
    </div>
    <div class="form-group">
      <label for="konu">Subject</label>
      <input type="text" class="form-control" name="konu" id="konu" required>
    </div>
    <div class="form-group">
      <label for="mesaj">Message</label>
      <textarea class="form-control" name="mesaj" id="mesaj" rows="3" required></textarea>
    </div>
    <input type="hidden" name="islem" value="gonder" required>
    <button type="submit" class="btn btn-primary">Send</button>
    </fieldset>
  </form>
  <aside>
    <h3>Location</h3>
    <iframe src="https://www.google.com/maps/embed?pb=!1m17!1m12!1m3!1d658.4309168065989!2d32.00941005065839!3d36.54806161318423!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m2!1m1!2zMzbCsDMyJzUzLjYiTiAzMsKwMDAnMzUuOSJF!5e0!3m2!1str!2str!4v1699341329906!5m2!1str!2str" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
  </aside>
</article>
     

验证码.php

<?PHP

$image = @imagecreatetruecolor(120, 30) or die("hata oluştu");

// arkaplan rengi oluşturuyoruz
$background = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
imagefill($image, 0, 0, $background);
$linecolor = imagecolorallocate($image, 0xCC, 0xCC, 0xCC);
$textcolor = imagecolorallocate($image, 0x33, 0x33, 0x33);

// rast gele çizgiler oluşturuyoruz
for ($i = 0; $i < 6; $i++) {
    imagesetthickness($image, rand(1, 3));
    imageline($image, 0, rand(0, 30), 120, rand(0, 30), $linecolor);
}

session_start();

// rastgele sayılar oluşturuyoruz
$sayilar = '';
for ($x = 15; $x <= 95; $x += 20) {
    $sayilar .= ($sayi = rand(0, 9));
    imagechar($image, rand(3, 5), $x, rand(2, 14), $sayi, $textcolor);
}

// sayıları session aktarıyoruz
$_SESSION['
captcha
'] = $sayilar;

// resim gösteriliyor ve sonrasında siliniyor
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>

验证码控制 .php 代码

<!doctype html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <title>CAPTCHA</title>
    <style>
        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }
    </style>

</head>
<body>

<br>

<strong>
    Robot olmadığınızı kanıtlamak için görseldeki metni yazın
</strong>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <div style='margin:15px'>
        <img src="captcha.php" id="capt">
        <input type=button onClick=reload(); value='Tekrar Yükle'>
    </div>


    <input type="text" name="deger"/>
    <input type="submit" value="Giriş" name="submit"/>
</form>

<div style='margin-top:5px'>
    <?php

    session_start();
    // Kullanıcı bir captcha verdiyse!
    if (isset($_POST['deger']))

        // Captcha geçerliyse
        if ($_POST['deger'] == $_SESSION['captcha'])
            echo '<span style="color:green">BAŞARILI</span>';
        else
            echo '<span style="color:red">
CAPTCHA 
BAŞARISIZ!!!</span>';
    ?>
</div>


<script type="text/javascript">
    function reload() {
        img = document.getElementById("capt");
        img.src = "captcha.php"
    }
</script>

</body>
</html>
php 联系人 验证码 联系表单

评论

0赞 CBroe 11/9/2023
“如果我关闭联系表格的操作部分” - 不确定这应该意味着什么。您似乎在第一个代码片段中将一个表单嵌套到另一个表单中,这在 HTML 中是不允许的。您需要将所有这些组合成一个形式

答: 暂无答案