jevchance Posted May 12, 2009 Share Posted May 12, 2009 Greetings, I'd like to get some advice on how to approach to a new project I am doing. The project is a PHP web application for an industrial manufacturer's sales force. It will be a sales quoting tool in the form of a questionnaire. The questions will be presented one at a time, and questions may be shown dependent upon previous choices. The questionnaire is quite lengthy, and by the end, the number of possible outcomes based on user input is large. Here's an example: Question 1: Choose a color: () Red () White () Blue Question 2: (if Red or White was chosen for question 1) Would you like a stand? () Yes () No (if Blue was chosen for question 1) Would you like a bracket? () Yes () No etc. etc. etc. I'd like this application to be a bit more elegant than an enormous listing of if/thens, so I'm considering forming a class for the questionnaire. The next problem I have is that since classes don't persist beyond page refreshes, I am also considering serializing the class and saving it to a database on each answer. This would also allow the salesperson to resume a saved session in case of interruption or browser crash. My first question is, do you think this would be the best way to approach this project? My second question is, are there any classes or libraries out on the web already available to handle this type of application? I Googled around a bit, but I honestly don't even know what to search for. I wonder if there's a 'name' for this type of application already that I don't know about, other than "progressive form". Thanks in advance for any help! Quote Link to comment https://forums.phpfreaks.com/topic/157842-php-progressive-questionnaire/ Share on other sites More sharing options...
JonnoTheDev Posted May 12, 2009 Share Posted May 12, 2009 You should use a session. You do not save an object to a database. Quote Link to comment https://forums.phpfreaks.com/topic/157842-php-progressive-questionnaire/#findComment-832533 Share on other sites More sharing options...
jevchance Posted May 12, 2009 Author Share Posted May 12, 2009 I know I can't save a class, but I can serialize the class and save that string to the database. As a user, wouldn't it infuriate you if you were 20 questions into a 30 question questionnaire and your browser crashed? Quote Link to comment https://forums.phpfreaks.com/topic/157842-php-progressive-questionnaire/#findComment-832550 Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 Well you can have a save button at the end of the page. If clicked, it saves progress. But if it's only 1 question at a time, I guess you can just save as the user goes along. Can the user ever go backwards? Saving a class and serializing it just to store in the DB is kind of stupid. That just makes it hard to query the DB for things you want. Quote Link to comment https://forums.phpfreaks.com/topic/157842-php-progressive-questionnaire/#findComment-832554 Share on other sites More sharing options...
jevchance Posted May 12, 2009 Author Share Posted May 12, 2009 Yes, a back function is necessary. What would be an alternative to serializing and storing the class? Is your recommendation to skip the class and just save individual question responses to the database? Well you can have a save button at the end of the page. If clicked, it saves progress. But if it's only 1 question at a time, I guess you can just save as the user goes along. Can the user ever go backwards? Saving a class and serializing it just to store in the DB is kind of stupid. That just makes it hard to query the DB for things you want. Quote Link to comment https://forums.phpfreaks.com/topic/157842-php-progressive-questionnaire/#findComment-832563 Share on other sites More sharing options...
Ken2k7 Posted May 12, 2009 Share Posted May 12, 2009 Is your recommendation to skip the class and just save individual question responses to the database? Yes. Why would you save a class in the db? Quote Link to comment https://forums.phpfreaks.com/topic/157842-php-progressive-questionnaire/#findComment-832564 Share on other sites More sharing options...
jevchance Posted May 12, 2009 Author Share Posted May 12, 2009 Yes I see what you're getting at, thanks for the reality check. Anyone else have any input? Thanks, and please keep it coming. Yes. Why would you save a class in the db? Quote Link to comment https://forums.phpfreaks.com/topic/157842-php-progressive-questionnaire/#findComment-832584 Share on other sites More sharing options...
JonnoTheDev Posted May 12, 2009 Share Posted May 12, 2009 Yes, your database structure should be designed to store the values of the user input i.e the answer chosen. This should be recorded after each submitted question to restore a previous session. You do not save objects to a database. Quote Link to comment https://forums.phpfreaks.com/topic/157842-php-progressive-questionnaire/#findComment-832798 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.