简体   繁体   English

提交时,HTML表单POST数据显示为空白

[英]HTML Form POST data shows as blank when submitted

I have a small form, once submitted the post data gets set to variables which are then used in a email message, when the email is sent, the post data is blank, when I try to echo out the POST data it is also blank. 我有一个小表格,提交后,发布数据将设置为变量,然后将其用于电子邮件中,发送电子邮件时,发布数据为空白,当我尝试回显POST数据时,它也为空白。 I am not sure why, here is the code. 我不确定为什么,这是代码。

   <?php if(!isset($_POST['submit'])): ?>
<form name="contactForm" method="POST" id="contactForm">
<table>
    <tr>
        <td><input name="name" id="name" class="fields" type="text" placeholder="name"></td>            
    </tr>
    <tr>
        <td><input name="email" class="fields" type="email" placeholder="email"></td>            
    </tr>
    <tr>
        <td><input name="phone" class="fields" type="phone" placeholder="phone(optional)"></td>            
    </tr>

    <tr>
        <td><textarea name="message" class="fieldsMessage" name="message" placeholder="Message"></textarea><?php $ermes; if(!empty($ermes)){echo "<br>".$ermes;}?></td>            
    </tr>

    <tr>
        <td><input class="submitButton" type="submit" name="submit" value="Submit">     
    </td>
    </tr>

 </table>
 </form>
 <?php else: ?>
<h2 style="padding-bottom: 80px; margin-bottom: 0px; text-align: center;" class="title">Your Message Was Sent</h2>
   <?php
    if(isset($_POST['submit'])){
        if(empty($_POST['name'])){
            echo "<script type=text/javascript>alert('PLEASE ENTER YOUR NAME');</script>";
        } //end name if
        elseif(empty ($_POST['email'])){
            echo "<script type=text/javascript>alert('PLEASE ENTER YOUR EMAIL');</script>";
        }//end else if email
        elseif(empty($_POST['message']))
        {
      echo "<script type=text/javascript>alert('Please enter a message');</script>";

        }// End elseif message
    }//End isset submit if
    else
    {
        $name=$_POST['name'];
        $email=$_POST['email'];
        $message=$_POST['message'];
        if(isset($_POST['phone']))
        {
         $phone=$_POST['phone'];   
        }// isset phone
        else
        {
            $phone="";
        }
        $to="sample@live.com";
        $subject="New Contact Form Email";
        $message="Name: ".$_POST['name'];
        $headers='From: Trip Galapagos Forms';
        mail($to, $subject, $message); 


    }//End else

?>
 <?php endif;?>

Where is the action in your form? 您所采取的行动在哪里?

The action attribute specifies where to send the form-data when a form is submitted. action属性指定提交表单时将表单数据发送到的位置。

Please refer html form tag for more information http://www.freecontactform.com/html_form.php#htmlform 请参考html表单标签以获取更多信息http://www.freecontactform.com/html_form.php#htmlform

Also check here and HTML_forms_-_the_basics 还要检查这里HTML_forms _-_ the_basics

You miss to close the if statement endif; 您错过了关闭if语句endif; in end of code. 在代码末尾。

If you didn't specify the action in form . 如果您未在form指定action Data will be posted in same location. 数据将发布在同一位置。

The action for form is missing. actionform缺失。 When you are posting data to the same page you have to use action="<?php echo $_SERVER['PHP_SELF']?>" or action="" in the form tag. 将数据发布到同一页面时,必须在表单标签中使用action="<?php echo $_SERVER['PHP_SELF']?>"action=""

Change 更改

<form name="contactForm" method="POST" id="contactForm">

to

<form name="contactForm" method="post" action="" id="contactForm">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM