PHP-如何以多页形式发送值 [英] PHP - How to send values in Multiple pages Form

查看:42
本文介绍了PHP-如何以多页形式发送值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在开发一个PHP应用程序中心(窗体),但是我陷入了困境.

So, I was working on a PHP Application Center (Form), and I'm stuck at something.

我有3页表格和1个sumbit页.全部都在.php扩展名中.因此,我想从第一页开始< input name ="name" type ="text" placeholder ="Name" required>

I have 3 pages of form and 1 sumbit page. All are in .php extention. So, I want to take the <input name="name" type="text" placeholder="Name" required> from page one and:

< label>关于您自己(至少50个字):< span> */span</label>< br/>< textarea name ="yourself" placeholder =关于您自己(至少50个字)"></textarea> 到提交页面.

我可以采用Textarea&来自第3页的文本框,可通过<?php echo $ _POST ['somethinghere']?> 提交页面.但是我无法从第一页和第二页中获取值.

I can take the values of Textarea & Textbox from page 3 to submit page through <?php echo $_POST['somethinghere']?>. But I can't take values from the First and second page.

以下是通过style.css(pastebin.com)指向我的php代码的链接:- http://pastebin.com/81vgHh5H

Here are links to my php codes with style.css (pastebin.com):- http://pastebin.com/81vgHh5H

推荐答案

我看了看Pastebin,我想我可以看到问题了.您将会话数据设置在它们要填写的同一页面上(因此,您要在尚未填写之前将这些字段分配给会话).您需要在第2页而不是第1页上执行此操作.因此,您的模式如下:

I had a look at the Pastebin and I think I can see the problem. You're setting the Session data on the same page that they're filling out (so you're assigning those fields to the session before they've even been filled in). You need to do that on page 2, not page 1. So your pattern is thus:

  1. 显示第1页的表单.
  2. 用户填写并点击提交.
  3. 将用户发送到第2页.
  4. 第2页获取从第1页发布的信息,并将其存储在会话中.
  5. 第2页显示第二个表单页面.
  6. 用户填写第2页,然后点击提交.
  7. 将用户发送到第3页.
  8. 第3页获取从第2页发布的信息,并将其存储在会话中.

依此类推...

到最后一页,会话将包含表单中的所有信息,然后您可以根据需要进行处理.

By the time you get to the last page, your session will contain all the information from the form and you can then process it however you need to.

示例:

第1页:

<form action="page2.php">
    <input type="text" name="page1text"/>
    <input type="submit"/>
</form>

第2页:

<?php
    $_SESSION['page1text'] = $_POST['page1text'];
?>
<form action="page3.php">
    <input type="text" name="page2text"/>
    <input type="submit"/>
</form>

第3页:

<?php
    $_SESSION['page2text'] = $_POST['page2text'];
?>
<form action="page4.php">
    <input type="text" name="page3text"/>
    <input type="submit"/>
</form>

第4页:

<?php
    $_SESSION['page3text'] = $_POST['page3text'];
?>
<ul>
    <li>Page 1: <?php echo $_SESSION['page1text'] ?></li>
    <li>Page 2: <?php echo $_SESSION['page2text'] ?></li>
    <li>Page 3: <?php echo $_SESSION['page3text'] ?></li>
</ul>

如您所见,最后进入第4页,可以访问前几页中的所有信息.

As you can see, page 4 winds up with access to all of the information from the previous pages.

以前的答案为:我建议使用一个包含表单所有属性的模型.当他们填写每个页面时,请使用用户输入的数据填充模型,然后当他们成功填写表单时,您可以销毁会话数据.

This answer previously read: I would recommend having a model that contains all of the form's properties. As they fill out each page, populate the model with the data the user has entered and then when they successfully complete the form you can destroy the session data.

这篇关于PHP-如何以多页形式发送值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆