[eluser]whobutsb[/eluser]
Hi All,
I'm working on building a surveying system for my company. And the way I designed it is modular with different functions doing different parts to put together the survey and its questions.
I have a function in the code that checks to see if a question is required and needs form_validation. The submission function looks like this:
Code:
function submitSurvey($surveyID){
//Load the Mdoels
$this->load->model('survey_model');
$this->load->model('question_model');
//Load the form validation
$this->load->library('form_validation');
//Select the survey information
$survey = $this->survey_model->select_survey($surveyID);
$this->survey_validation($surveyID);
//Run the validation
if ($this->form_validation->run() == FALSE){
$this->takeSurvey($surveyID);
}
else{
echo "Success";
}
} //end submitsurvey function
And the survey_validation function looks like this:
Code:
//Check if validation is needed
function survey_validation($surveyID){
//Get the questions
$questions = $this->survey_model->select_survey_questions($surveyID);
$config = array();
//Set the form validation
foreach($questions as $question){
if($question->questionRequired){
//Get the Question Title
$questionDetails = $this->question_model->select_question_details($question->questionID);
//Create a rule for that question
$config[] = array(
'field' => "$question->questionID",
'label' => $questionDetails->questionTitle,
'rules' => 'required'
);
}
}
$config[] = array(
'field' => 'email',
'label' => 'Email Address',
'rules' => 'required|valid_email'
);
$this->form_validation->set_rules($config);
}
In my validation script do I need to return anything? The Validation is working so I'm guessing not but the repopulation of the fields is not happening. I have a function that also builds the questions and I added the set_values and the set_selects to them. I just can't seem to figure out how to get everything to repopulate.