Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4604210
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:15:45+00:00 2026-05-22T00:15:45+00:00

i am working on a application for making exams. I have 3 tables (exams/questions/options)

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T00:15:46+00:00Added an answer on May 22, 2026 at 12:15 am

    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:

    foreach ($questions as $i => $question) {
        echo $this->Form->input('Exam.'.$i.'.question_id', array('type' => 'hidden', 'value' => $question['Question']['id']));
        echo $this->Form->input('Exam.'.$i.'.answer');
    }
    echo $this->Form->end('Finish!');
    

    This is important so that you have all questions in one array.

    What you do now in your function could look something like this:

    function validate_answer() {
        if (isset($this->data)) {
            foreach ($this->data['Exam'] as $exam) {
                $this->Exam->Question->id = $exam['question_id'];
                $correct_answer = $this->Exam->Question->field('correct_answer');
                $user_answer = $exam['answer'];
                if ($correct_answer == $user_answer) {
                    //do something with it
                }
            }
        }
    }
    

    This just for the basics. Hope this helps to get you in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an working application. Now I want to change the table names of
I making web application for iphone user. I have HTML table structure inside asp.net
I have to start working on a project that involves making an application with
I have been working on making an application for editing game plugins for a
I am making an application using two view controlers. When I am working on
I have a working application using python and zeromq and I would like to
I am working on splitting out an existing, working application that I currently have
I am working on application for Ipad.in this application i have a UIButton on
I currently have an application making use of Authorize.net's ARB API. I have everything
I am working on making an application that will store information, and for user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.