Jump to content
Larry Ullman's Book Forums

I Need Help Validating Questions And Answers In A Survey


Recommended Posts

Hi all,

 

I need some help validation questions and answers in a survey.

 

I have a survey that can take x number of questions and each questions can have x number of answers.

 

questions 1

answer 1

answer 2

answer3

 

question 2

answer 1

answer 2

answer3

 

 

The questions and their associated answers are coming from the database so I don't know the the values fof each questions and the values of each answer.

How do I test to make sure the user selected one answer from each question and get the values?

 

Bahaa,

Link to comment
Share on other sites

Create the questions as an array in your html: question[X]. Put the actual question ID in for each X. Store the IDs of the questions displayed in the session. Upon form submission, use the session values to know what to validate.

Link to comment
Share on other sites

Thanks for your answer

I understand the part of creating the questions as an array but I don't understand the part of validating upon submission.

 

Could you please give me an example?

Link to comment
Share on other sites

So, when the page is loaded, you can do this:

$_SESSION['questions'] = array(1, 23, 49, 14);

Then, when the form is submitted, you do a foreach loop on $_SESSION['questions']:

foreach ($_SESSION['questions'] as $id) {
   // Validate $_POST['question'][$id].
}

Link to comment
Share on other sites

 Share

×
×
  • Create New...