简体   繁体   English

我不知道联系表有什么问题

[英]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.

相关问题 我不知道“渲染”有什么问题 - I don't know what's wrong with 'render' 当我点击按钮时,我不知道怎么了 - I don't know what's wrong when i click the button nothing work 不知道我的 IF 语句有什么问题(JAVASCRIPT) - Don't know what's wrong with my IF statement (JAVASCRIPT) 我不知道我的编码有什么问题。 (javascript) - I don't know what's wrong with my coding. (javascript) 这个联系表格代码有什么问题? - What's wrong with this contact form code? 我在制作 loginPage 时从控制台收到错误,但我不知道出了什么问题(React.js) - i got error from console while making loginPage but i don't know what's wrong (React.js) TypeError: undefined is not a function(靠近'...(0,_react.useCallBack)...')。 我不知道我的代码中的 usCallBack() function 有什么问题 - TypeError: undefined is not a function (near '...(0, _react.useCallBack)...'). I don't know what's wrong with the usCallBack() function in my code 我没有弄明白我的JavaScript代码有什么问题 - I don't get what's wrong with my Javascript code jQuery:小绑定/悬停代码片段,几行长,不知道出了什么问题 - Jquery: Small bind hover/unbind snippet of code, few lines long, don't know what's wrong 元素在我的代码中不会.fadeTo。 不知道怎么了JavaScript,JQuery,HTML - elements wont .fadeTo in my code. Don't know what's wrong JavaScript, JQuery, HTML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM