如何将第1页的输入字段传递到第2页的隐藏字段,然后在javascript中显示第2页到第3页的隐藏字段?

时间:2017-11-24 18:58:23

标签: javascript php session cookies

我需要将第1页的以下信息传递给第2页的隐藏文件。第2页添加了其他信息,所有输入字段必须显示在第3页? 第1页位于registration.html:

之下
<form method="POST" action="interests.php" onsubmit="return checkForm(this);">
        <p>Use tab key to move from one input field to the next.</p>
        <label for="userName">Username:</label>
        <input type="text" name="username" placeholder="Enter your Username" /><div><span id='errorusername'></span></div>

        <label for="passWord1">Password:</label>
        <input type="password" name="pwd1" placeholder="Enter your Password" /><div><span id='errorpwd1'></span></div>

        <label for="passwordword2">Verify your Password:
        </label>
        <input type="password" name="pwd2" placeholder="Enter in your Password again" /><div><span id='errorpwd2'></span></div>

        <label for="firstName">First Name:
        </label>
        <input type="text" name="firstName" placeholder="Enter your First Name" /><div><span id='errorfirstName'></span></div>

         <label for="lastName">Last Name:
        </label>
        <input type="text" name="lastName" placeholder="Enter your Last Name" /><div><span id='errorlastName'></span></div>

        <label for="email">Email:
        </label>
        <input type="text" name="email" placeholder="Enter your Email Address" /><div><span id='erroremail'></span></div>

        <label for="phone">Phone Number
        </label>
        <input type="text" name="phone" placeholder="Enter your Phone Number" /><div><span id='errorphone'></span></div>



        <input type="submit" name="submit" value="Next Step">

    </form>

第2页如下:

form method="POST" action="confirm.php" onsubmit="return checkForm(this);">

        <p><label>Interest:</label></p>
        <input type="checkbox" name="fund" value="fund"/><span>Fund Raising</span>
        <input type="checkbox" name="sponsor" value="sponsor" /><span>Sponsorship</span>
       <input type="checkbox" name="vol" value="vol" /><span>Volunteer</span><div></div>

        <p><label for="signUpNewsletter">Sign up for newsletter:
        </label></p>
        <input type="radio" name="signUpNewsletter" value="Yes"> Yes 
        <input type="radio" name="signUpNewsletter" value="No"> No

        <p><label for="desc">Comments:</label></p>
        <textarea name="desc" id="desc" rows="10" cols="30"></textarea>

        <p><label for="referred"> Referred by:</label></p>
        <input type="text" name="referred" />
       <?php
            if(isset($_POST["submit"]))
        {
            $username= $_POST["username"];
            $pwd1= $_POST["pwd1"];
        }
        ?>

        <input type="hidden" name="username" value="<?php echo $_POST["username"]; ?>">
        <input type="hidden" name="pwd1" value="<?php echo $_POST["pwd1"]; ?>">
        <input type="hidden" name="pwd2" value="<?php $_POST["pwd2"]; ?>">
        <input type="hidden" name="firstName" value="<?php echo $_POST["firstName"]; ?>">
        <input type="hidden" name="lastName" value="<?php echo $_POST["lastName"]; ?>">
        <input type="hidden" name="email" value="<?php echo $_POST["email"]; ?>">
        <input type="hidden" name="phone" value="<?php echo $_POST["phone"]; ?>">
        <input type="hidden" name="fund" value="<?php echo $_POST["fund"]; ?>">
        <input type="hidden" name="sponsor" value="<?php echo $_POST["sponsor"]; ?>">
        <input type="hidden" name="vol" value="<?php echo $_POST["vol"]; ?>">
        <input type="hidden" name="sign" value="<?php echo $_POST["sign"]; ?>">


        <input type="submit" name="submit1" value="Register">
    </form>

需要显示从第1页和第2页输入的信息:

<section id="pageFormContent">

    <p>You have successfully registered!</p>

    <?php

        if(isset($_POST["submit1"]))
       {
            $username= $_POST["username"];
            $pwd1= $_POST["pwd1"];
            $pwd2= $_POST["pwd2"];
            $firstName= $_POST["firstName"];
            $lastName= $_POST["lastName"];
            $email= $_POST["email"];
            $phone= $_POST["phone"];
            $fund= $_POST["fund"];
            $sponsor= $_POST["sponsor"];
            $vol= $_POST["vol"];
            $sign= $_POST["sign"];
            echo $username;
            echo $pwd1;
            echo $pwd2;
            echo $firstName;
            echo $lastName;
            echo $email;
            echo $phone;
            echo $fund;
            echo $sponsor;
            echo $vol;
            echo $sign;
         }




    ?>



</section>

按下提交按钮时,显示的唯一内容是&#34;您已成功注册!&#34; 谁能告诉我为什么数据没有显示?

2 个答案:

答案 0 :(得分:0)

在第2页中,将隐藏值从<?php echo $username; ?>更改为<?php echo $_POST['username']; ?>并尝试发布

<input type="hidden" name="username" value="<?php echo $_POST['username']; ?>">
<input type="hidden" name="password" value="<?php echo $_POST['pwd1']; ?>">
<input type="hidden" name="passwordVerify" value="<?php $_POST['pwd2']; ?>">
<input type="hidden" name="firstName" value="<?php echo $_POST['firstName']; ?>">
<input type="hidden" name="lastName" value="<?php echo $_POST['lastName']; ?>">
<input type="hidden" name="email" value="<?php echo $_POST['email']; ?>">
<input type="hidden" name="phone" value="<?php echo $_POST['phone']; ?>">

答案 1 :(得分:0)

您需要在下一行添加$ _POST [“用户名”]并在其余行中添加尊重字段而不是 “&GT; 当前没有设置$ username变量。