Javascript提交不发送POST到php文件 [英] Javascript Submit is not Sending POST to php file

查看:116
本文介绍了Javascript提交不发送POST到php文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让我的javascript超链接按钮将数据发布到我的php表单电子邮件脚本中。我尝试了几种不同的方式,但似乎没有任何工作。任何帮助表示赞赏。

我的表单代码:

 <表单ID =formaction =contactform.phpmethod =POSTenctype =text / plain> 
< fieldset>
< label>< strong>您的名称:< / strong>< input id =nametype =textname =name> < /标签>
< label>< strong>您的电话号码:< / strong>< input id =phonetype =textname =phone>< / label>
< label>< strong>您的电子邮件:< / strong>< input id =emailtype =textname =email>< / label>
< label>< strong>您的讯息:< / strong>< textarea id =messagename =message>< / textarea>< / label>
< div class =btns>< a href =contacts.htmlclass =button>清除< / a>< a href =#onclick =document.getElementById ( '形式')提交();类= 按钮 >置于< / A>< / DIV>
< / fieldset>
< / form>

Contactform.php:

 <?php 

var_dump($ _ POST);

if(isset($ _ POST ['form'])){


$ name = $ _POST ['name'];
$ phone = $ _POST ['phone'];
$ visitor_email = $ _POST ['email'];
$ message = $ _POST ['message'];


$ email_from ='emailaddress@gmail.com';
$ email_subject =联系表单提交;
$ email_body =名称:$ name \\\
。 电话:$ phone \\\
。 消息:$消息;


$ to ='emailaddress@gmail.com';
$ headers =From:$ email_from \r\\\
;
$ headers。=回复:$ visitor_email \r\\\
;
邮件($ to,$ email_subject,$ email_body,$ headers);

回声感谢您的关注,我会尽快与您联系。;

} else {
echo它没有用。;
}


?>

另外,我只在php的开头有var_dump用于调试目的。不会成为最终代码的一部分。

解决方案

删除 enctype =text / plain 来自form标签,PHP不支持它。



请参阅:方法= QUOT;交" ENCTYPE = QUOT; text / plain的"不兼容?


I am having trouble getting my javascript hyperlink button to post data to my php form email script. I have tried doing it several different ways, but nothing seems to work. Any help is appreciated. Thank you.

My form code:

<form id="form" action="contactform.php" method="POST" enctype="text/plain" >
      <fieldset>
        <label><strong>Your Name:</strong><input id="name" type="text" name="name">       </label>
        <label><strong>Your Phone Number:</strong><input id="phone" type="text" name="phone"></label>
        <label><strong>Your E-mail:</strong><input id="email" type="text" name="email"></label>
        <label><strong>Your Message:</strong><textarea id="message" name="message"></textarea></label>
        <div class="btns"><a href="contacts.html" class="button">Clear</a><a href="#" onclick="document.getElementById('form').submit();" class="button">Send</a></div>
      </fieldset>  
    </form>

Contactform.php:

<?php

    var_dump($_POST);

    if (isset($_POST['form'])) {


    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $visitor_email = $_POST['email'];
    $message = $_POST['message'];


    $email_from = 'emailaddress@gmail.com';
    $email_subject = "Contact Form Submission";
    $email_body = "Name: $name\n" . "Phone: $phone\n" . "Messge: $message";


    $to= 'emailaddress@gmail.com';
    $headers= "From: $email_from \r\n";
    $headers.= "Reply-To: $visitor_email \r\n";
    mail($to,$email_subject,$email_body,$headers);

    echo "Thank you for your interest. I will contact you shortly.";

    }else{
    echo "It didn't work.";
    }


    ?>

Also, I have the var_dump at the beginning of the php for debugging purposes only. Not going to be a part of the final code.

解决方案

Remove enctype="text/plain" from the form tag, PHP doesn't support it.

See: method="post" enctype="text/plain" are not compatible?

这篇关于Javascript提交不发送POST到php文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆