i am working on a application for making exams.
I have 3 tables (exams/questions/options)
exams table : id,name
questions table : id,name,exam_id
options tables : id,name,question_id
exams hasMany questions hasMany options.
Now, i set my questions with the related options and then add it to the exam. So far so good.
But, when i want to do the exam i am stuck in the validation process.
e.g i have a do_exam.ctp with the following code:
<?php echo $form->create(null, array('action' => 'validate_answer')); ?>
<h3>Do Exam</h3>
<?php if(!$questions) {?>
<h4>No Questions Found!</h4>
<?php } ?>
<?php foreach($questions as $question):?>
<h4>Question</h4>
<?php echo $question['Question']['qst']; ?>
<h4>Make an Option</h4>
<?php
$i = 0;
foreach ($question['Option'] as $option):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $option['Type'];?></td>
<td><?php echo $option['opt'];?></td>
<br />
<?php endforeach; ?>
<br />
<?php $options = array('A' => 'A', 'B' => 'B','C' => 'C', 'D' => 'D');
echo $form->select('answer', $options);
echo $form->hidden('ca', array('value' => $question['Question']['Correct_Answer'] ));
?>
<?php endforeach; ?>
<?php echo $form->end('Finish!'); ?> `
and at the exams controller i want to validate if it is the correct answer. I don’t want to store it anywhere just check if the answer is correct or not.
any help?
There’s no need to store the correct answer if you don’t want the user to have the option to keep track of his progress.
I’m sure you have somewhere in your question or in your option some column like
correct_answer. Don’t put it as a hidden field in your form. Every little kid who can use the sourcecode-view could see the correct answer.At first you have to write your input like this in your foreach:
This is important so that you have all questions in one array.
What you do now in your function could look something like this:
This just for the basics. Hope this helps to get you in the right direction.