dongyou7472 2013-02-26 14:14
浏览 33
已采纳

PHP5 - 向导样式提交数据

I have a multi-step form that I have spread across 4 separate pages - in other words, 4 sections (I chose this method as it would be far too complex to process all my fields on one page). In my MySQL DB I have a table for each of the sections on each page (step1, step2, step3, step4). After submitting the first page I would like to insert my Page1 data to the DB and have it return the Primary Key, which I aim to then post to the next page (step2.php) ... and the same process will follow for Step3 and Step4.

The tables for Step2, Step3 and Step4 in the DB all have a Primary Key (reg_id) which are also all Foreign Keys to step1.reg_id.

I would like some advice/suggestions please on how to:

  1. Post data back to my DB after each page submit (Do I post back to the same page, or have a separate processor page to handle that?)
  2. Redirect to the next page
  3. Pass the reg_id returned from Step1 to the Next Step pages

I am using plain and simple PDO to get my data in MySQL. I admit that I don't have a lot of PHP knowledge to accomplish this as I am too used to the lifecycle of ASP.NET webforms development, hence my asking for your expertise here.

Much appreciated as always!

  • 写回答

2条回答 默认 最新

  • douyan4470 2013-02-26 14:42
    关注

    As Karl said in his comment, it makes the most sense to save the form values as $_SESSION values before redirecting to the next page. The form processor then accesses the values from $_SESSION, just as if you had sent them as $_POST values.

    To expand a bit on why this is a bit better, you have to think about what would happen if your users don't just go from page 1 to page 2... to the end of the form in one sitting. What if someone exits the wizard partway through? What if they need to go back and edit values, sometimes multiple times? In short, if your users have a workflow that results in either incomplete forms or the user going back and forth between form pages, you might end up with an awful lot of unnecessary validation and writes to the database.

    If you save the form values in the session and only store them in the database when the user completes the entire multi-page form, you remove the possibility of these unnecessary writes to the database.

    It also makes it easy for people to go backwards in the form to make edits without breaking your validation which you've indicated is a bit complicated. Ex. suppose a value x on page 1 is related to a value y on page 4. The user gets all the way to page 5 but then decides that they want to go back to page 1 to edit x. Page 1 has access to the session, and therefore has access to both x and y -- you could, for example, warn them if their new x value would make y invalid, or something along those lines.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度