简体   繁体   English

PHP的形式2步骤确认

[英]php form 2 step confirmation

i try to challenge my self but i stuck( I try to create a php form with 2 steps confirmation: 我试图挑战自我,但我坚持了(我尝试创建一个具有2个步骤的确认的php表单:

  1. When the user fill up the form and hit Submit, it checks all the conditions(name, pass etc.). 当用户填写表格并点击Submit(提交)时,它将检查所有条件(名称,通过等)。 If everything ok automatically redirecting the user. 如果一切正常,则自动重定向用户。

  2. After redirecting (to the same page) the user can check all the details again. 重定向到同一页面后,用户可以再次检查所有详细信息。 If they ok, hit again the submit button which redirects to the final page. 如果一切正常,请再次单击提交按钮,该按钮将重定向到最后一页。

I stuck on the 2nd phase...how to redirect to the final page? 我停留在第二阶段...如何重定向到最后一页?

I'm very beginner so i'm curios what could be done better or any advise. 我是一个初学者,所以我很想知道什么可以做得更好或任何建议。

<?php
 // the php code 
session_start();


if ($_SERVER['REQUEST_METHOD'] == "POST") {

// setting up the variables

$title = $_POST['title'];
$fName = trim(filter_input(INPUT_POST,'fName', FILTER_SANITIZE_STRING));
$lName = trim(filter_input(INPUT_POST,'lName',FILTER_SANITIZE_STRING));
$age = intval($_POST['age']);


$_SESSION['title'] = $title;
$_SESSION['fName'] = $fName;
$_SESSION['lName'] = $lName;
$_SESSION['age'] = $age;



//checking for possible errors
if ( $fName == "" || strlen($fName) <= 2 ) {
    $errorMsg1 = "<span>Provide your First name!(minimum 3 characters)</span>";
    $status = false;

}
else if ( $lName == "" || strlen($lName) <= 2 ) {
    $errorMsg2 = "<span>Provide your Last name!(minimum 3 characters)</span>";
    $status = false;

}
else if ( $age < 18 ) {
    $errorMsg3 = "<span>You must be 18 or above!</span>";
    $status = false;

}

else {  $status = true; }

// redirecting to done page

if ($status) {
    header("Location:TEST ZONE.php?status=awaiting");
    }
  }

 ?>
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<div id="wrapper">
<?php

if ( isset($_GET['status']) && $_GET['status'] == "awaiting" ) {
    echo "<form>"
    . "Check your Details!<br>"
    . $_SESSION['title'] . "<br>"
    . $_SESSION['fName'] . "<br>"
    . $_SESSION['lName'] . "<br>"
    . $_SESSION['age'] . "<br>"
   // **NOW WHEN I'M in the awaiting phase, i don't know what to do(**

    . "<input type='submit' name='submit'/>";

    echo "</form>";
   }

   else {  ?>
    <form action="TEST ZONE.php" method="post">
    <h3>Register Form </h3>

    <label for="title">Title </label>
    <select name="title">
        <option name="mr">Mr</option>
        <option name="ms">Ms</option>
    </select><br><br><br>
    <label for="fName">First Name</label><br>
    <input type="text" name="fName" id="fName" value="<?php if    (isset($fName)) { echo $fName; } ?>"><br><?php
    if (isset( $errorMsg1 )) {
        echo $errorMsg1;
    }
    ?><br><br>

    <label for="lName">Last Name</label><br>
    <input type="text" name="lName" id="lName" value="<?php if (isset($lName)) { echo $lName; } ?>"><br><?php
    if (isset( $errorMsg2 )) {
        echo $errorMsg2;
    }
    ?><br><br>

    <label for="age">Age</label><br>
    <input type="text" name="age" id="age" value="<?php if (isset($age)) { echo $age; }?>"><br><?php
    if (isset($errorMsg3)){
        echo $errorMsg3;
    } ?><br><br>
    <input type="submit" value="Submit"><input type="reset">

</form> <?php } ?>
  </div>



 </body>
</html>

Add action in your form to redirect final page. 在表单中添加操作以重定向最终页面。

You already have all values in session so you can access it in final page also 您已经在会话中拥有所有值,因此您也可以在最后一页中访问它

<?php

 // the php code 
session_start();


if ($_SERVER['REQUEST_METHOD'] == "POST") {

// setting up the variables

$title = $_POST['title'];
$fName = trim(filter_input(INPUT_POST,'fName', FILTER_SANITIZE_STRING));
$lName = trim(filter_input(INPUT_POST,'lName',FILTER_SANITIZE_STRING));
$age = intval($_POST['age']);


$_SESSION['title'] = $title;
$_SESSION['fName'] = $fName;
$_SESSION['lName'] = $lName;
$_SESSION['age'] = $age;



//checking for possible errors
if ( $fName == "" || strlen($fName) <= 2 ) {
    $errorMsg1 = "<span>Provide your First name!(minimum 3 characters)</span>";
    $status = false;

}
else if ( $lName == "" || strlen($lName) <= 2 ) {
    $errorMsg2 = "<span>Provide your Last name!(minimum 3 characters)</span>";
    $status = false;

}
else if ( $age < 18 ) {
    $errorMsg3 = "<span>You must be 18 or above!</span>";
    $status = false;

}

else {  $status = true; }

// redirecting to done page

if ($status) {
    header("Location:TEST ZONE.php?status=awaiting");
    }
  }

 ?>
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<div id="wrapper">
<?php

if ( isset($_GET['status']) && $_GET['status'] == "awaiting" ) {
    echo "<form action='final_page.php'>"
    . "Check your Details!<br>"
    . $_SESSION['title'] . "<br>"
    . $_SESSION['fName'] . "<br>"
    . $_SESSION['lName'] . "<br>"
    . $_SESSION['age'] . "<br>"
   // **NOW WHEN I'M in the awaiting phase, i don't know what to do(**

    . "<input type='submit' name='submit'/>";

    echo "</form>";
   }

   else {  ?>
    <form action="TEST ZONE.php" method="post">
    <h3>Register Form </h3>

    <label for="title">Title </label>
    <select name="title">
        <option name="mr">Mr</option>
        <option name="ms">Ms</option>
    </select><br><br><br>
    <label for="fName">First Name</label><br>
    <input type="text" name="fName" id="fName" value="<?php if    (isset($fName)) { echo $fName; } ?>"><br><?php
    if (isset( $errorMsg1 )) {
        echo $errorMsg1;
    }
    ?><br><br>

    <label for="lName">Last Name</label><br>
    <input type="text" name="lName" id="lName" value="<?php if (isset($lName)) { echo $lName; } ?>"><br><?php
    if (isset( $errorMsg2 )) {
        echo $errorMsg2;
    }
    ?><br><br>

    <label for="age">Age</label><br>
    <input type="text" name="age" id="age" value="<?php if (isset($age)) { echo $age; }?>"><br><?php
    if (isset($errorMsg3)){
        echo $errorMsg3;
    } ?><br><br>
    <input type="submit" value="Submit"><input type="reset">

</form> <?php } ?>
  </div>

final_page.php final_page.php

<?php
session_start();
$title = $_SESSION['title'];
$fName = $_SESSION['fName'];
$lName = $_SESSION['lName'];
$age = $_SESSION['age'];
?>

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

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