如何在另一个html页面上调用数据(输入到html表单)?

时间:2013-07-07 00:37:52

标签: php html web

这是低位:

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

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

我将如何进行此操作以及我将使用哪种编码?我精通HTML,但刚刚学习PHP,所以细节很受欢迎。

以下是我的编码示例:

HTML PAGE WITH FORM:

                            <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 SCRIPT:

    <?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.');
}

请帮忙!

2 个答案:

答案 0 :(得分:0)

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

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

在您重定向的页面中,您使用php和$_GET['param1'] , $_GET['param2']来获取您的值。看到你重定向到的页面是一个PHP而不是一个HTML,因为它有PHP代码。

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

P.S通过重定向,我指的是header()函数。

答案 1 :(得分:0)

您在HTML表单中使用method = POST,因此PHP中的$_POST数组中提供了内容。执行var_dump($_POST);查看您的数据。电子邮件的价值在$_POST['email']

中提供

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