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

时间:2014-05-15 06:30:10

标签: php

我有一个小表单,一旦提交后将数据设置为变量,然后在电子邮件中使用,当发送电子邮件时,发布数据为空白,当我尝试回显出POST数据时也空白。我不知道为什么,这是代码。

   <?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;?>

3 个答案:

答案 0 :(得分:3)

您表单中的操作在哪里?

操作属性指定在提交表单时发送表单数据的位置。

请参阅html form tag了解更多信息http://www.freecontactform.com/html_form.php#htmlform

同时检查hereHTML_forms_-_the_basics

答案 1 :(得分:1)

您错过了在代码末尾关闭if语句endif;

如果您未在action中指定form。数据将发布在同一位置。

答案 2 :(得分:0)

action的{​​{1}}丢失了。当您将数据发布到您必须使用的同一页面时

表单中的formaction="<?php echo $_SERVER['PHP_SELF']?>"

更改

action=""

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