简体   繁体   English

验证成功完成后,重定向到email.php页面

[英]after validation successfully completed redirect to email.php page

Here i'm trying to send a contact form values to email id. 在这里,我正在尝试将联系表单值发送到电子邮件ID。 I've posted contact.php page code. 我已经发布了contact.php页面代码。 I've done server side validation on same page. 我已经在同一页面上完成了服务器端验证。 After validation successfully completed it should redirect to email.php page. 验证成功完成后,应重定向到email.php页面。 How should i do? 我应该怎么做?

Contact.php Contact.php

 <?php
    $errname = "";
    $errmotorcycle = "";
    //some codes

    if($_POST["contacts"] == "all")
    {
        // name validation
        if(empty($_POST["name"]))
        {
            $errname = '<span class="error">Should not be empty</span>';
        }
        else if(preg_match("/^[a-zA-Z ]+$/", $_POST["name"]) === 0)
        {
            $errname = '<span class="error">Name must be from letters and spaces only</span>';
        }
        else
        {
            $errname = '';
        }
        // motorcycle validation
        if($_POST["typeofmotor"] == "empty")
        {
            $errmotorcycle = '<span class="error">You must select one option</span>';
        }
        //some codes
    }
 ?>

<html>
<head><title></title></head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
<input type="hidden" name="contacts" value="all" />
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="281" height="40" class="rightalign">Name : </td>
    <td width="268"><input type="text" name="name" class="normal" value="<?php $_POST['name']; ?>" /></td>
    <td width="431" valign="middle"><?php if(isset($errname)) echo $errname; ?></td>
  </tr>
 //some codes
</table>
</form>
</body>
</html>

After sending the eMail, you could redirect the browser like that: 发送电子邮件后,您可以像这样重定向浏览器:

<?php
header('Location: http://www.example.com/email.php');
die();
?>

If you choose that solution, please keep in mind that headers may only be sent before any content is sent to the browser. 如果选择该解决方案,请记住,仅在将任何内容发送到浏览器之前才发送标头。

You can't redirect to another script and use the POST vars as well, because they will be lost after the redirect. 您不能重定向到另一个脚本,也不能使用POST变量,因为重定向后它们将丢失。 You can include the email.php script: 您可以包括email.php脚本:

<?php
include( dirname( __FILE__ ) . "/email.php");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM