I've had a potential job come through that I want to run on Craft, but I'm a bit sketchy about one particularly bit. The site is going to include educational modules and tests for each. Test results will be stored in their profile which can be reviewed the admins. I know how to create a new entry for each test submission, but the thing I'm not sure about is this:

How can I store whether a question was answered correctly or not? Is there a way to display a score based on the test result?

As always, I'm not a plugin developer... if this can be done with template logic that would be perfect.


This is a very broad question, and I'm not sure you're going to get a very good answer without being more specific. Whether or not this is possible without the aid of a plugin would entirely depend on how you designed the system, and what the needs are. I can certainly imagine ways to accomplish this without the use of a plugin. With that said, I also think that you could probably make for a much more robust system with a better user experience with the aid of some simple plugins. But I also wouldn't let plugins scare you. Writing a plugin is surprisingly easy (depending on the complexity of course). As a front-end developer myself, I have written several with little difficulty, so I can attest to this. I would focus on designing a system that makes the most sense from a user perspective and then build it accordingly, even if that means learning to write some simple plugins.

As a starting point (without plugins) you might try and approach the problem this way.

  • Create a channel (or structure if multiple tests are used; using a test/question hierarchy) to store question entries, which would include the question, possible answers, and the correct answer (i.e. structure with handle 'tests' or 'modules' or whatever you want to call it).
  • Create a channel for user submitted answers with the user's answer and related fields to store a reference to the original question, and the user that submitted the answer (i.e. channel with handle 'testResults' or whatever you want to call it).
  • Create a form that presents a question (from the 'tests' structure) and the possible answers (as a radio button for example if multiple choice) that gets submitted to the 'testResults' channel.
  • Include hidden fields on the form with the question id, and user id, to populate the corresponding related 'entries' and related 'users' fields in the 'testResults' entry.
  • In the form success redirect you can load the form submission as well as the original question/answer, compare them and display if they are correct or not.
  • In the user profile template, you can then load all test entries (questions) and testResult entries (answers) for that user and compare them to display both whether specific questions were answered correctly and their overall test score.

Note that the data is not stored as part of the user profile per se; rather the user is only associated to the data via a related user field. And if you always look up the questions and answers and compare them to get the score then there would be no real need for a plugin. Where you might want a plugin is if you want to store the test results independently, or their overall progress, or other summary data, etc. But like I said above, writing a plugin to do this is not that complicated.

This assumes of course that the admin would view the user's profile and Q&A via the front-end. This is also by no means the only way, just an example of how it might be done.

  • Thanks for the encouragement Douglas. I've done a few similar things before but plugin development does scare me! I'll have to embark on learning how to do it anyway independently of this project I think. That being said, your answer is how I'd intended to approach it but lays it out clearly, thank you! Jan 9 '15 at 11:06

The catch is, it sounds like you need to add an entry and modify user data all in a single shot. That's not really possible out-of-the-box... different forms will submit to different places.

One possible solution is to create an intermediary page:

  1. First page is your test form,
  2. Upon submission, creates a new entry. (Edit an Entry)
  3. Then redirects to a second page,
  4. Second page displays the results, and offers to "Save the results",
  5. Upon submission, saves results to user profile. (Edit a User Profile)

It's pretty rough, to be honest. If you know any PHP at all, I'd highly recommend using this project to teach yourself a little plugin development. If you build some customized Controllers and Services to handle this data, you'll end up with a far more robust solution.

Sounds like a fun project... Let us know what architecture you decide to go with!

  • Hey Lindsey. Didn't see your answer before I started mine. But I agree with you - a plugin of some kind would probably be helpful here. Jan 9 '15 at 1:30
  • Thanks for your answer Lindsey - I think some plugin learning might be in order regardless of this project! I've done some PHP in the past... might be time to dig it up again. Jan 9 '15 at 11:07
  • Glad to help. I think once you dive into plugin dev, you'll find it's actually not too scary (after you get past the initial learning curve). And like @Douglas said in his answer, it will greatly expand the amount of things you can do with your site. Good luck with your project!
    – Lindsey D
    Jan 9 '15 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.