javascript - Creating a multi-page PHP form with sessions - Stack Overflow

I need to create a pretty extensive form with PHPMySQL with a lot of conditional logic that ultimately

I need to create a pretty extensive form with PHP/MySQL with a lot of conditional logic that ultimately ends with submission to the MySQL database. So basically the user makes their first choice with a radio button (has to be because they are "choosing" pictures) and then gets taken to the next "page" of the form based on that submission. That submission ALSO has to be stored in a session or cookie because at the end of the form I will gather all of their input and populate a row in the database. What should my approach be? Right now I'm writing forms that store the POST data in a SESSION and then populate the database row at the end, but as soon as I introduce conditional logic from page to page, the sessions break and don't get sent. Any help would be greatly appreciated.

I need to create a pretty extensive form with PHP/MySQL with a lot of conditional logic that ultimately ends with submission to the MySQL database. So basically the user makes their first choice with a radio button (has to be because they are "choosing" pictures) and then gets taken to the next "page" of the form based on that submission. That submission ALSO has to be stored in a session or cookie because at the end of the form I will gather all of their input and populate a row in the database. What should my approach be? Right now I'm writing forms that store the POST data in a SESSION and then populate the database row at the end, but as soon as I introduce conditional logic from page to page, the sessions break and don't get sent. Any help would be greatly appreciated.

Share Improve this question asked Oct 13, 2010 at 18:49 Rob BennetRob Bennet 4771 gold badge9 silver badges21 bronze badges 2
  • 3 Have you considered using javascript? Have one big form that is broken up by tabs or something, but it's all on the same page still? – hookedonwinter Commented Oct 13, 2010 at 18:52
  • 1 Also, you're more likely to get an answer if you accept answers to your previous questions. – hookedonwinter Commented Oct 13, 2010 at 18:55
Add a ment  | 

3 Answers 3

Reset to default 2

I did exactly this with a 250 question psychological test system. Once you think it through, it's not too difficult. The solution I used was to output in stacked divs rather than worrying about doing individual pages and posting to session--it's cleaner. A submit button lives on every div, but it only submits on the last one--a function showsthe next div and hides the current div upon click in every other "page". Using variables and PHP math, I can set the test to e out in different binations--such as 1 page of 250, 5 pages of 50, etc. Your most difficult logic goes into building the page with the proper number of questions and making sure the divs are effectively titled to work with your show/hide script. In my case, I use Jquery's show/hide functionality. Works like a charm.

Because this solution uses one page, you don't have to worry about values being "forgotten" when they go back or forth. In my case, I don't even allow the user to go back because I don't give them any UI to do so. A back click on the browser would give them a warning that they'll be leaving the page. However, you could use several different methods to allow them to go back including UI such as a button, or setting up the back functionality using the browser's back button. A huge side benefit is that loading is next to nothing, and page changes are instantaneous to the user.

Sounds like a classic "wizard" interface. A quick google search brought up this, but I'm not sure if it's any good.

http://www.phpclasses/browse/file/8308.html

The advantage of saving all data to a single update at the end of the wizard is simplicity. The advantage of writing to the DB after each step is that the user can e back and finish the wizard at a later date - you're not tied to the current user session.

If you're inclined to go with the "insert at the end" approach I'd remend bpeterson76's idea of using JS to show / hide sections on a singler phisical form - just make sure you've got control of the user's back button, otherwise the user could loose all of their answers.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745312226a4622050.html

相关推荐

  • javascript - Creating a multi-page PHP form with sessions - Stack Overflow

    I need to create a pretty extensive form with PHPMySQL with a lot of conditional logic that ultimately

    9小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信