通过表单执行.php和.html


Execute .php and .html via form

我有这个联系表格:

<form class="contactform" action="contact.php" method="post">
    <table>
        <tr><td>Name</td></tr>
        <tr><td><input type="text" name="name"></td></tr>
        <tr><td>Phonenumber(optional)</td></tr>
        <tr><td><input type="text" name="telephone"></td></tr>
        <tr><td>E-mail</td></tr>
        <tr><td><input type="text" name="email"></td></tr>
        <tr><td>Your question or comment</td></tr>
        <tr><td><textarea name="comment"></textarea></td></tr>
    </table>
    <input type='submit' name='sending' value='Submit'>
</form>

当用户单击提交时,它会转到一个php脚本,该脚本会将联系人表单的详细信息发送给我,这发生在action="contact.php"。但我想要一个单独的html页面,一个"谢谢你的问题"页面。如何通过action或其他方式执行2个文件。

谢谢。

一旦您的联系人表单完成了它需要做的事情,就将其重定向到感谢页面。

contact.php

// Your stuff here
header("location: /thank-you.php"); // Assumes thank-you.php is in server root
exit();

谢谢.php

<html>
<body>
<h1>Thank you</h1>
<p>Stuff stuff stuff!</p>
</body>
</html>

在contact.php中处理完表单数据后,重定向到感谢页面:header('Location: '.'thankyou.php');

只需在处理完数据之后或之前,在contact.php的末尾使用print("thanks for you question");即可。您无法将其发送到2个不同的页面/文件。

请求处理完成后,在contact.php文件中添加header("location:thankyou.html");