M
M
Minningt2015-11-07 16:49:24
PHP
Minningt, 2015-11-07 16:49:24

How to install captcha?

Hi all. I set up a captcha on the site, everything is displayed, checked, but how to make the result "True or False" written opposite the field with the captcha input, and not in another file specified in the form action. The page with the form itself is located on desription.php?id=, and if the form contains an address with a handler in the comment.php file, then it goes to comment.php and just shows an inscription there. This does not fit. And if TRUE, then we write data to the database, otherwise false.
Button click code. In the comment.php file

session_start();
  if(isset($_POST['send'])) {
    if ($_SESSION["code"] == $_POST["captcha"]) {
     echo 'true';
    $name     = $_POST['com_name'];
    $email    = $_POST['com_email'];      
    $query = 'INSERT INTO comments (name, email) VALUES (:name, :email)';
    $stmt = $pdo->prepare($query);
    $stmt->execute(array( ':name'=>$name, ':email'=>$email));
    header("Location: ".$_SERVER["HTTP_REFERER"]);
    } 
    else {
      echo 'false';
    }
  }
unset($_SESSION['capcha']);

<form id="comment" method="post" action="#">
      <div class="com_line">
        <label for="com_name" >Имя</label> 
        <input name="com_name" type="text" value="" />
      </div>
        <div class="com_captcha">
          <input class="com_inp captcha" id="captcha" name="captcha" type="text" >
          <img src="/captcha.php" class="img-captcha" />
          <span class="reload"></span>
        </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
inDeepCode, 2015-11-08
@inDeepCode

You need to submit form data via ajax

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question