0

这是低调:

我有一个带有我创建的表单的 HTML 页面。不确定这是否重要,但我会说信息是使用 HTML 验证的,而不是 PHP。当用户提交他们的信息时,它会被发送到一个 PHP 脚本,在该脚本中信息会通过电子邮件发送给我。然后,该 PHP 脚本重定向到 HTML“谢谢”页面。

正是在这个感谢页面上,我想回忆他们的信息并在页面上“回显”它,以便他们可以打印出来。

我将如何做这件事以及我将使用什么编码?我精通HTML,但刚刚学习PHP,因此感谢详细信息。

下面是我的编码示例:

带表格的 HTML 页面:

                            <form id="contact-form" action="contact-form_emailer.php" method="post">
                            <table width="497" border="0" id="table-contact">
                                <tr>
                                    <td colspan="2" class="form-header">Contact Us</td>
                                </tr>
                                <tr>
                                    <td colspan="2" class="required-notice">Fields marked with a <font color="#e3202a">*</font> are required.</td>
                                </tr>
                                <tr>
                                    <td class="form-item">Date:<font color="#e3202a">*</font></td>
                                    <td><input type="text" id="date" name="date" disabled><script type="text/javascript">document.getElementById('date').value = (new Date()).format("mmmm dd, yyyy");</script></td>
                                </tr>
                                <tr>
                                    <td class="form-item">Time:<font color="#e3202a">*</font></td>
                                    <td><input type="text" id="time" name="time" disabled><script type="text/javascript">document.getElementById('time').value = (new Date()).format("h:MM tt");</script></td>
                                </tr>
                                <tr>
                                    <td class="form-item">First Name:<font color="#e3202a">*</font></td> 
                                    <td><input type="text" min="2" size="40" name="fname" required></td>
                                </tr>
                                <tr>
                                    <td class="form-item">Last Name:<font color="#e3202a">*</font></td>
                                    <td><input type="text" min="2" size="40" name="lname" required></td>
                                </tr>
                                <tr>
                                    <td class="form-item" style="vertical-align:top;" rowspan="2">Preferred Method of Contact:<font color="#e3202a">*</font></td>
                                    <td><input type="radio" name="method-of-contact" value="email" required checked>Email</td>
                                </tr>
                                <tr>
                                    <td><input type="radio" name="method-of-contact" value="phone" required>Phone</td>
                                </tr>
                                <tr>
                                    <td class="form-item">Phone:<font color="#e3202a">*</font></td>
                                    <td><input type="tel" pattern="...-...-...." placeholder="xxx-xxx-xxxx" size="40" name="phone" required></td>
                                </tr>
                                <tr>
                                    <td class="form-item">Email:<font color="#e3202a">*</font></td>
                                    <td><input type="email" placeholder="someone@somewhere.com" size="40" name="email" required></td>
                                </tr>
                                <tr>
                                    <td class="form-item" style="vertical-align:top;">Message:</td>
                                    <td><textarea cols="31" rows="5" placeholder="Enter your message here." name="message"></textarea></td>
                                </tr>
                                <tr>
                                    <td style="text-align:center;" colspan="2"><input type="submit" value="Submit"></td>
                                </tr>
                            </table>
                      </form>

PHP脚本:

    <?php 


//Email Content

$to = "My.Email";  //<-----Email Address to which form is emailed

$email_subject = "New CONTACT Form Submission from $fname $lname";

$email_body = 'The following information was submitted using the CONTACT form.'.
"Date: $date \n ".
"Time: $time \n ".
"First Name: $fname \n ".
"Last Name: $lname \n ".
"Preferred Method of Contact: $method-of-contact \n ".
"Phone: $phone \n ".
"Email: $email \n ".
"Message: $message \n ";

mail($to,$email_subject,$email_body);


//Redirect to the CONFIRMATION page
//header('Location: contact-form_submit.html');

if(mail($to, $subject, $message, $headers)) {
header('Location: contact-form_submit.html');
} else {
    die('Unfortunately there was a problem submitting your form. Please try again or       contact us via email or telephone.');
}

请帮忙!

4

2 回答 2

0

有两种方法。第一个是在重定向用户的 url 中传递参数。

contact-form_submit.php?param1=value1&param2=value2...

在您重定向的页面中,您使用 php 并$_GET['param1'] , $_GET['param2']获得您的值。请注意,您重定向到的页面是 php 页面而不是 html 页面,因为其中包含 php 代码。

第二个是回显整个页面而不是重定向。

PS 通过重定向我指的是 header() 函数。

于 2013-07-07T01:20:52.053 回答
0

您在 HTML 表单中使用 method=POST,因此内容$_POST在 PHP 的数组中可用。执行 avar_dump($_POST);查看您的数据。email 的值在$_POST['email'].

请注意,HTML 不会验证数据。当然,某些浏览器可能会尊重您的 HTML 属性,并且可能某些 JavaScript 会验证这些字段,但您必须始终假设您从用户那里获得的数据可能是恶意的。

于 2013-07-07T01:25:29.180 回答