Hey,
In my quest for perfection and minimalism, I post this question here to you
> guys, seeking if there is a better and more alternative option than the one
> I have.
> I have a module with two different templates. Essentially the first is a
> quiz template, the second is a page that displays the results of the quiz.
> The quiz is a form whereas the results page is not. On my quiz page, the
> action for the form is essentially 'module/quizResults?id='.$quizId
> Now for the quiz action, I do a db query to retrieve the set of questions
> that belong to the quiz and then when the post takes place the action that
> is being called is that of quizResults, out here I must compare the answer
> options of my user against the correct answer options for the questions of
> a quiz. Essentially, I have to again query the db to retrieve the set of
> questions for the quizzes in another db. I feel this is a slight overkill
> and I am irked.
> I think there can be better solutions. I can post back to the same quiz
> page, but then that demands more complexity on the template as well as the
> action making things a little murkier.
> Any alternatives? Unless this is the way to go about it and I am probably
> just overthinking it.
This is what I would normally do:
- The action that creates the form also validates and handles it.
- Yes, you have to query the database each time this action is called. Do
not worry about it. If you do, use memcache to query the result and make it
faster. This would make your site a lot more complicated though.
- If the user has finished the quiz correctly redirect to a result page.