public function validate() { $return = true; if ($this->survey_question_id == "") { $this->errors[] = "You must enter a survey question ID"; $return = false; } if (!$this->question) { $this->question = SurveyQuestion::find_by_id($this->survey_question_id); } if ($this->question) { // We now need to validate the answer depending on the question if (in_array($this->question->type, array('sqtTextbox', 'sqtTextArea'))) { if (!$this->value && $this->question->required) { $this->errors[] = "You must enter an answer for question {$this->question->position}"; $return = false; } elseif ($this->question->regex) { if (preg_match($this->question->regex, $this->value)) { $this->errors[] = "Answer for question {$this->question->position} is invalid"; $return = false; } } } } else { $this->errors[] = "Unable to find the survey question"; $return = false; } if (count($this->errors) > 0) { $return = false; } return $return; }
protected static function load_question($survey, $id = null) { if (!$id) { $id = $_GET['question_id']; } $object = SurveyQuestion::find_by_id($id); if ($object and $object->survey_id == $survey->id) { return $object; } else { Error404(); } }