bahaa Posted May 2, 2012 Share Posted May 2, 2012 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 More sharing options...
Larry Posted May 2, 2012 Share Posted May 2, 2012 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 More sharing options...
bahaa Posted May 3, 2012 Author Share Posted May 3, 2012 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 More sharing options...
Larry Posted May 3, 2012 Share Posted May 3, 2012 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 More sharing options...
bahaa Posted May 3, 2012 Author Share Posted May 3, 2012 Thank you so much Larry. Evrything works fine now. Link to comment Share on other sites More sharing options...
Recommended Posts