[英]I don't know what's wrong with contact form
I'm new to web development, and i need help with this contact form.我是 Web 开发的新手,我需要有关此联系表的帮助。 I'm using a bootstrap template.
我正在使用引导程序模板。
Sorry guys for posting mistakes, I'm new here, and i i'm a little confused about posting and editing.抱歉,发布错误的人,我是新来的,我对发布和编辑有点困惑。
Here is my PHP code:这是我的PHP代码:
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message']);
// $human = intval($_POST['human']);
$from = 'Demo Contact Form';
$to = 'info@artgate.me';
$subject = 'Message from Contact Demo ';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
//Check if simple anti-bot test is correct
//if ($human !== 5) {
// $errHuman = 'Your anti-spam is incorrect';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! I will be in touch</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>
JS Code
JS代码
function contactForm(){
$('.btn-submit').on('click',function(e){
var $this = $(this);
e.preventDefault();
$.ajax({
url : 'contact.php',
type : 'POST',
data : $this.closest('.contact-form').serialize(),
success : function(data){
if ($(data).is('.send-true')){
$this.addClass('loading').delay(650).queue(function(){
$this.addClass('success').addClass('loaded').dequeue();
});
} else {
$this.addClass('error');
}
$this.delay(500).queue(function(){
$this.removeClass('loaded').removeClass('loading').dequeue();
});
$this.delay(400).queue(function(){
if ($(data).is('.send-true')){
$this.removeClass('success').closest('.contact-form').trigger('reset');
} else {
$this.removeClass('error');
}
$this.dequeue();
});
}
});
});
}
try changing your php from this:尝试从此更改您的 php:
if (isset($_POST["submit"])) {
to this:对此:
if (isset($_POST["btn-submit"])) {
If you named your submit button "btn-submit" then your POST will contain a variable called "btn-submit"如果您将提交按钮命名为“btn-submit”,那么您的 POST 将包含一个名为“btn-submit”的变量
In the comments, you said that your HTML code for your button was this:在评论中,您说按钮的 HTML 代码是这样的:
<button type="submit" data-hover="Send" class="btn btn-default progress-button btn-submit"><span class="button-label">Send</span></button>
What you need is a "Name" property.您需要的是“名称”属性。 So it should look like this:
所以它应该是这样的:
<button type="submit" data-hover="Send" name="sendform" class="btn btn-default progress-button btn-submit"><span class="button-label">Send</span></button>
Once you edit that, you need to change编辑后,您需要更改
if (isset($_POST["submit"])) {
To到
if (isset($_POST["sendform"])) {
This should make it work now.这应该使它现在工作。
if (isset($_POST["submit"])) {如果(isset($_POST[“提交”])){
To if (isset($_POST["submit_button_name"])) {如果 (isset($_POST["submit_button_name"])) {
then i will work for you i think那么我会为你工作,我想
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.