【问题标题】:How do I pass input fields from page 1 to hidden fields on page 2 and then display hidden fields from page 2 to page 3 in javascript?如何将输入字段从第 1 页传递到第 2 页的隐藏字段,然后在 javascript 中显示从第 2 页到第 3 页的隐藏字段?
【发布时间】:2018-05-08 19:02:10
【问题描述】:

我需要将以下信息从第 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>

第3页需要显示第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>

当提交按钮被按下时,唯一显示的是“您已成功注册!” 谁能告诉我为什么数据没有显示?

【问题讨论】:

  • 进行了更改,但代码仍然无法在第三页上显示信息。还有其他建议吗?

标签: javascript php session cookies


【解决方案1】:

在第 2 页将隐藏值从 &lt;?php echo $username; ?&gt; 更改为 &lt;?php echo $_POST['username']; ?&gt; 并尝试发布

<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']; ?>">

【讨论】:

  • 我做了上面的修改,仍然只显示“您已成功注册!”
【解决方案2】:

您需要在下一行添加您的 $_POST["username"] 并在其余部分添加相关字段,而不是 "> $username 变量当时没有设置。

【讨论】:

  • 我进行了更改,但仍然无法在第三页上正确显示信息。可能是第三页没有检索数据的错误?
  • 您是否检查了第二页是否设置了隐藏值?
  • 第 2 页表格前还缺少一个“
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-22
  • 2020-05-13
  • 1970-01-01
  • 2018-08-23
相关资源
最近更新 更多