So the answers are hard-coded into the snippet. (1974,195cm,Brown,Melted)
I want to replace those values with the longtitle tag from various resources, to make it easier to manage the answers.
e.g. I want to replace 1974 with the longtitle field of resource 10 (who’s value is 1974).
So I’m thinking of something like this:
$answerOne = $modx->getObject(‘modResource’, 10)->get(‘description’);
Looks good (though that’s not the longtitle field). Do you need separate scores? Otherwise you could total them in the snippet, using just one value $score and $score++.
Thanks bob. Yes I changed the field because I was using the longtitle for the question in the end.
I will try what you said about combining the scores though. Thanks.
It would certainly work, but it would make editing them kind of tedious.
I think I’d store all the questions and answers in one place, say a resource or chunk with tokens at the beginning of each question and answer (Q: and A:), then parse that. The EZfaq extra uses that method.
Another way, if your writing them yourself, would be to just create a .php file with an associative array of questions and answers and “include” it in your code.
Thanks Bob - I think i’ll go with using clientConfig because I can get my head roudn the method!!
So I’ve created my config values and pulled them into the form.
But in the snippet which calculates the score, I have this - which I think must be wrong, because it’s not scoring correctly:
if($one == '[[++Q1-correct]]') { $score1 = '1'; }
So [[++Q1-correct]]’ Is the correct score in clientConfig.