PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Creating a Self Assessment Test

  1. I know there are bunch of other threads for quizes and tests and whatnot, but from the looks of it, a new thread is preferred for each case, so that's why I started this one:

    I have a test that's broken into 9 categories. Each category contains 10 questions, and each question has 2 options that are assigned either 1 or -1. Depending on the sum of each 10 question segment, I need to show 1 of 2 possible responses.

    The confirmation form would be generic, and the results would be sent via email to look something like this:

    In category 1, your results indicate that... (option 1 or option 2)
    In category 2, ...
    ...

    I know this is possible to do and perhaps not even that complicated, but I'm no php/javascript coder and I need some help with the framework to make it happen.

    This code from another thread has the closest solution I've found so far, but I'm unsure about how to modify it to do what I'm looking for:

    http://pastebin.com/SKBNHtza

    I'm more than willing to get my hands dirty, but I could really use some direction from support on this. Little help?

    Thanks,
    Tyler

    Posted 13 years ago on Friday November 18, 2011 | Permalink
  2. Where do you want to display the results? On the confirmation page and in the email notification?

    Posted 13 years ago on Friday November 18, 2011 | Permalink
  3. Just in the email. The confirmation page/message would be generic, saying something like, "Check your email for your personal analysis."

    Posted 13 years ago on Friday November 18, 2011 | Permalink
  4. What you could do then is add hidden fields to your form to store the "Results" for whatever you want to calculate. Then use the gform_pre_submission hook and custom code to perform your calculations and store the results in the hidden fields you added.

    Posted 13 years ago on Friday November 18, 2011 | Permalink
  5. Thanks Carl. I am really a newb with PHP and hooks. Could you take a look at that code that I linked to in the first post and just tell me if that's a good framework to build from?

    Obviously I'll have to figure out the details on my own, but if I have a good starting point, I'm much more likely to be successful.

    Posted 13 years ago on Tuesday November 22, 2011 | Permalink
  6. Hi Tyler. I wrote that code. I'd be happy to answer any specific questions about it. Have you tried to implement anything yet, or gotten stuck?

    Thanks.

    Posted 13 years ago on Wednesday November 23, 2011 | Permalink
  7. Hi Chris,

    Well, with a little head scratching, I was able to get all the calculations to work. Hooray! Now, I just need to figure out how to spit out different variables based on those calculations in an email.

    I'm dissecting that code you wrote, and I *kind of* understand it, but that's written for a confirmation page, and not for an email. I assume it works mostly the same, but I'm not quite sure what I need to change and how to format the notification email.

    Any advice on that would be greatly appreciated.

    Posted 13 years ago on Wednesday November 23, 2011 | Permalink
  8. I will check in with you on Wednesday. Thanks

    Posted 13 years ago on Wednesday November 23, 2011 | Permalink
  9. Sounds good, Chris. If you're not able to get to it today, have a good Thanksgiving and we can pick it up on the next business day.

    Posted 13 years ago on Wednesday November 23, 2011 | Permalink
  10. Hi Chris. Hope you had a good Thanksgiving. I know you're busy and I'm not in a hurry. I just wanted to make sure this didn't sink too far. :)

    Posted 13 years ago on Monday November 28, 2011 | Permalink
  11. Hi Tyler. Thanks for bumping the post. I lost it for a while.

    There are two separate functions there. The first one, ch_awesomeness_rating takes the values that are submitted, does some math, then stores them in the entry, so they can be referred to later. That's the function you will modify to perform your math and it will be hooked to the gform_pre_submission because we need to modify values before the entry is stored and before the notifications are sent.

    On line 44 there begins another function, ch_courage_confirmation, which is using the values which were calculated and stored in the entry. That function is hooked to the gform_confirmation filter, to modify the confirmation. You will probably NOT be using this second function at all, because you need to modify the notification (referred to as the autoResponder). So, you will have two things going on, both hooked to the gform_pre_submission hook. Here is some code I used to change the autoResponder based on form values. You can probably incorporate this into your function: http://pastebin.com/Sb8PSPyX

    And you can read more about the autoResponder which is part of the $form object, here:
    http://www.gravityhelp.com/documentation/page/AutoResponder

    If you need more help, please post the code you have tried at pastie.org or pastebin.com and we'll see what we can do.

    Thanks for your patience.

    Posted 13 years ago on Tuesday November 29, 2011 | Permalink
  12. Hi Chris,

    Thanks for that. I tried using a some elements from that first bit of code (that I referenced in the original post) and this most recent piece to create the email notification customization that I need, but when I try to paste it into my custom_functions.php file (Headway theme), I get a parse error and have to go in via ftp to fix it.

    I know this is the right place to put the php because the code that is doing the calculations is in the same place and is working correctly. I can only guess that I've mangled something since I'm basically fumbling in the dark.

    Here's the frankenstein php I've created: http://pastebin.com/B5LM6bj9

    Could you take a look and maybe point out where I've messed it up. Any other advice you can offer, like "will it actually work?" would be very helpful as well.

    Thanks,
    Tyler

    Posted 13 years ago on Wednesday November 30, 2011 | Permalink
  13. Okay, scratch that last reply. There's an erroneous comma in the function that's causing the parse error.

    After testing, though, it appears that the code is definitely not working...

    Posted 13 years ago on Wednesday November 30, 2011 | Permalink
  14. Chris, here's the latest php I've put together to try to get the email notification working but, alas, it produces nothing:

    http://pastebin.com/FcWxbDtv

    Any idea what I'm doing wrong here?

    Posted 13 years ago on Thursday December 1, 2011 | Permalink
  15. It looks like you are trying to use $lead but that's not available here in the pre_submission hook. You only have $form to work with. Assuming the values are being stored properly in your entry (the calculated values) you will have to access them like this:

    [php]
    ')
    if (rgpost('input_122') > -30)
                    $score_overall = 'This is conditional answer #2.';

    You don't have an $entry yet since it has not been created. Use the rgpost function to get the value of the $_POST variables safely, and assuming the values are stored in those fields, you will be fine.

    Instead of $lead[113] your variables are going to look more like rgpost('input_113'). If you need to, dump the $_POST variable and see where everything is being stored, or, check and entry to be sure you are using the right numbers.

    I think you're close. Keep at it.

    Posted 13 years ago on Friday December 2, 2011 | Permalink
  16. Thanks Chris! I don't understand 90% of what you just said, but I'm pretty sure I get the 10% that matters most. :)

    Posted 13 years ago on Friday December 2, 2011 | Permalink
  17. Well, I guess I didn't understand enough...

    I updated all of the variables from $lead[xxx] to rgpost('input_xxx'), but the notification email still comes through blank.

    The calculations in the other function are not being done the way I intended, but they *are* being done. Values are being stored in the empty hidden fields in the form; I can see them in the entries. Since there are values there, albeit the wrong ones, the notification, in theory, should still spit out one of the conditional results.

    Alas, that doesn't happen, so something else must be incorrect.

    Here's one more pastebin link with both functions in it so that you can see the whole shebang:

    http://pastebin.com/RfQ1LAwG

    I know I'm close to having this thing licked....

    Posted 13 years ago on Friday December 2, 2011 | Permalink
  18. I am wondering about line 4 and line 78. You call it as an action once, and a filter the other time. Because the values are being stored, it looks like you have the first part correct, line 4 through 75. The documentation for gform_pre_submission calls it an action hook as well.

    I would first try changing line 78 to call it as add_action rather than add_filter, and see if that works.

    Posted 13 years ago on Friday December 2, 2011 | Permalink
  19. Line 78 changed to add_action, but no difference in the result. :(

    Updated php: http://pastebin.com/MhfSEcPE

    Thanks for your continued support.

    Posted 13 years ago on Friday December 2, 2011 | Permalink
  20. Can you export the form for me and I will install it with this code and take a look?

    One thing I don't know is if you can use and action hook like that twice? Maybe all the code needs to be in the first hook so it all runs at one time. I think that makes sense, but I don't really know the answer to that. If you will export the form and email it to chris@rocketgenius.com I will take a look and try it out.

    Thanks,
    Chris

    Posted 13 years ago on Friday December 2, 2011 | Permalink
  21. It's in your inbox. Thanks, Chris.

    Posted 13 years ago on Friday December 2, 2011 | Permalink
  22. I replied to your email. Let me know if that works for you and we'll post the solution here.

    Posted 13 years ago on Sunday December 4, 2011 | Permalink
  23. Thanks for the reply, Chris. I've been testing it and just responded to you. Unfortunately, it's still not working... I'd love to be able to post the solution here once we get it so that others can benefit from it.

    Posted 13 years ago on Wednesday December 7, 2011 | Permalink
  24. Alright. With a ton of help from Chris, we have a properly functioning test that:

    1. Calculates scores and stores them in hidden fields on the form, and
    2. Sends an email with conditional text based on the score from each hidden field.

    Here's the code: http://pastebin.com/xJmhrVUN

    I hope this is helpful for anyone else trying to put together a complicated quiz, test, or assessment.

    I'll post the form this code was intended for so you can see how it works once it's ready for prime time.

    Posted 13 years ago on Sunday December 11, 2011 | Permalink
  25. Thanks for the update Tyler. Please do post when the form and scoring are complete.

    Posted 13 years ago on Sunday December 11, 2011 | Permalink

This topic has been resolved and has been closed to new replies.