[英]PHP form that shows secret page when user submits name & email
I'm basically trying to create a form that collects a users name, email and company, mails that information to me, and then opens up a secret page to them. 我基本上是想创建一个收集用户名,电子邮件和公司的表单,然后将这些信息邮寄给我,然后向他们打开一个秘密页面。 I think I'm on the right track, hoping you guys can help me out. 我认为我走在正确的轨道上,希望你们能帮助我。
Form: 形成:
<form id="form1" action="submit.php" method="post">
<label for="name-id" >Full Name</label>
<input id="name-id" name="name-id" type="text"/>
<label for="email-id" >Email</label>
<input id="email-id" name="email-id" type="text"/>
<label for="company-id" >Company Name</label>
<input id="company-id" name="company-id" type="text"/>
<input type="submit"/>
</form>
PHP: PHP:
<?php
$name = $_POST["name-id"];
$email = $_POST["email-id"];
$company = $_POST["company-id"];
if($name != null && $company != null && filter_var($email, FILTER_VALIDATE_EMAIL){
echo "all forms filled";
mail("me@me.com", "subject - success", "body - someone passed");
include ("secretpage.php");
exit();
} else {
include ("homepage.php");
} ?>
Max, 马克斯
You should redirect your customer to secretpage or homepage instead of include files in a same page. 您应该将客户重定向到保密页或首页,而不是在同一页面中包含文件。
You can do it by using javascript, window.location="secretpage.php" or window.location="homepage.php" depends upon an authentication. 您可以使用javascript,window.location =“ secretpage.php”或window.location =“ homepage.php”来完成此操作,具体取决于身份验证。
If your code is not working remove "filter_var($email, FILTER_VALIDATE_EMAIL)" from your if condition. 如果您的代码不起作用,请从您的if条件中删除“ filter_var($ email,FILTER_VALIDATE_EMAIL)”。 write error_reporting(E_ALL) and ini_set("display_errors",1) at the top of your page code, which will help to track an error. 在页面代码的顶部写入error_reporting(E_ALL)和ini_set(“ display_errors”,1),这将有助于跟踪错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.