简体   繁体   English

Session 页面之间的变量

[英]Session Variables Between Pages

I've got two pages with many text box inputs containing numbers.我有两个页面,其中包含许多包含数字的文本框输入。
The first page's form submits to the second page (where the text box values become session vars) and the second page submits all of the session vars to a processing page where they're added to the database.第一个页面的表单提交到第二个页面(其中文本框值变为 session vars),第二个页面将所有 session vars 提交到处理页面,然后将它们添加到数据库中。

I'm trying to make it where you can go back and forth between page 1 and 2, and all of your text values entered will stay the same.我正在尝试在第 1 页和第 2 页之间来回移动 go,并且输入的所有文本值都将保持不变。

This works for coming back to the first page because the second page initiates the variables and takes the POST.这适用于返回第一页,因为第二页启动变量并接受 POST。

However, I can't achieve the same effect going from the second page back to the first, and then back, because the second page only submits to the processing page.但是,从第二页回到第一页,然后再返回,我无法达到相同的效果,因为第二页只提交到处理页面。 Example:例子:

<div style="width:800px;text-align:LEFT;margin:0 auto;padding-bottom:5px;">
  <input type="submit" value="<-- Back to Parts A-C" style="border:none;background-color:transparent;color:blue;text-decoration:underline">
</div>
<div style="width:800px;text-align:right;margin:0 auto;padding-bottom:5px;">
  <input type="submit" value="Save Report" /></form></p>
</div>

I'm trying to find a way for Page 1 to be able to receive the text box inputs from page 2. Any suggestions?我正在尝试为第 1 页找到一种能够从第 2 页接收文本框输入的方法。有什么建议吗?

I solved a similar problem by putting the values that the user enters in session immediately when they submit any form, even if it's not the final form before saving to the database.我通过在用户提交任何表单时立即将用户输入的值放入 session 解决了类似的问题,即使它不是保存到数据库之前的最终表单。

I've never used php, but you should be able to write some code like this:我从来没有使用过 php,但你应该可以写一些这样的代码:

<input type='text' name='txtName', value={if name in session, print name here, otherwise ""} />

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

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