Answer the question
In order to leave comments, you need to log in
How to fix add error? Field lighting?
Once again, hello everyone. In general, I figured out the captcha, it is checked if the input is incorrect, but !!!
1. When I enter characters incorrectly, the form is updated. How to fix?
2. When I enter everything correctly, how to add data to the database? At the moment, through ajax, it just writes emptiness (such as success)
3. How to highlight the field with a red frame if it is empty, and not write an alert? And you need to highlight what is empty
File check_capcha
session_start();
if ($_SESSION["code"] == $_POST["captcha"]) {
if (isset($_POST["send"])) {
$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));
}
}
else {
die("Wrong TEXT Entered");
}
$('#send_com').click(function() {
var name = $('#name').val();
var email = $('#mail').val();
var captcha = $("#captcha").val();
if (name == '' || mail == '' || captcha == '')
{
alert("Fill All Fields");
return false;
}
else
{
var dataString = 'captcha=' + captcha;
$.ajax({
type: "POST",
url: "check_captcha.php",
data: dataString,
success: function(html) {
alert(html);
}
});
}
});
Answer the question
In order to leave comments, you need to log in
1. When I enter characters incorrectly, the form is updated. How to fix?
success: function(html) {
alert(html);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question