HTML - 一页上的多个联系表单

时间:2015-05-27 13:07:58

标签: php html forms

当我将两个联系表单添加到同一页面时,我遇到了问题

第一个联系表格:

<form action="contact-form.php" method="POST">
<input type="date" id="datepicker" name="date">
<input type="time" id="time" name="time">
<select name="people" id="selectEdit">
    <option value="1">One</option>
    <option value="2">Two</option>
</select>
<input type="text" name="name" placeholder="Full Name">

<input type="submit" value="Reserve table" name="reservationsubmit" class="send">
</form>

这是第二种形式:

<form action="contact-form.php" method="POST">
<input type="text" id="thepearlname" name="thepearlname" placeholder="Name*">
<input type="email" id="thepearlemail" name="thepearlemail" placeholder="Email*">
<textarea name="thepearlmessage" id="thepearlmessage" placeholder="Message*"></textarea>
<input type="submit" value="Send message" class="sendMessage" name="contactsubmit">
</form>

第一种形式本身可以正常工作,但是当我添加第二种形式时,它们都不起作用,一旦我点击提交,我只得到以下消息: &#34;错误!&#34;

这是我的contact-form.php

的内容
<?php 
if(isset($_POST['reservationsubmit'])){
    //Reservation Form
    if (empty($_POST["date"]) || empty($_POST["time"]) || empty($_POST["people"]) || empty($_POST["name"])) {
        echo 'is empty';
    } else {
        $reserve_to = "my.mail@gmail.com";
        $reserve_subject = "New reservation";

        $date = $_POST['date'];
        $time = $_POST['time'];
        $people = $_POST['people'];
        $reserve_name = $_POST['name'];

        $formcontent="Name: $reserve_name \nDate: $date \nTime: $time \nTable for: $people";

        mail($to, $subject, $formcontent) or die("Error Reservation!");

        echo "Thank you!";
    }
}
else if (isset($_POST['contactsubmit'])){
    //Contact Form
    if (empty($_POST["thepearlname"]) || empty($_POST["thepearlemail"]) || empty($_POST["thepearlmessage"])) {
        echo 'is empty';
    } else {
        $contact_to = "my.mail@gmail.com";
        $contact_subject = "New Contact Inquiry";

        $name = $_POST['thepearlname'];
        $email = $_POST['thepearlemail'];
        $message = $_POST['thepearlmessage'];

        $contact_formcontent="Name: $name \nEmail: $email \nMessage: $message";

        mail($contact_to, $contact_subject, $contact_formcontent) or die("Error Contact!");

        echo "Thank you!";


    }
} 
?>

任何人都可以引导我走向正确的方向或建议可能导致问题的原因吗?

当我添加print_r($ _ POST);在第一个之前如果我得到以下内容:

Array ( [date] => 2015-05-28 [time] => 22:22 [people] => 3 [name] => Jane Doe [reservationsubmit] => Reserve table ) Error Reservation!

3 个答案:

答案 0 :(得分:1)

首先更改此项,然后尝试

mail($reserve_to, $reserve_subject, $formcontent) or die("Error Reservation!");

答案 1 :(得分:1)

哥们, 取代

2015-05-27 23:59:00.000

通过

mail($to, $subject, $formcontent) 

答案 2 :(得分:0)

删除if if并将其替换为if