Welcome Guest, Not a member yet? Register   Sign In
Problem using Form Validation library
#8

[eluser]whobutsb[/eluser]
Sorry about not giving more information about the problem. Here is the thread I started yesterday. http://ellislab.com/forums/viewthread/121691/

Basically what I have done is create a Surveying system that dynamically creates questions for the survey taker depending on either a survey session ID or a surveyID. The difference between the two is with the survey session id we already have their contact information, from a excel list, or a database table. I'm building the questions dynamically in a function

Code:
$data['survey_questions'] = $this->questions->build_survey_questions($surveyID)
;

The output of this I send to the view. I also have another function that sets the form validation. I call it like this:
Code:
$this->validation->survey_validation($surveyID);

But functions are in there own libraries, and called within the controller. When I create the questions I always set the value using one of the form_validation set_value(), set_radio, set_dropdown, etc. No matter if there is required questions or not. Here is a sample of how I create the questions.

Code:
function build_survey_questions($surveyID){
        
        $CI =& get_instance();
        
        $CI->load->model('question_model');
        
        $survey_questions = '';
        //Get the survey questions
        $surveyQuestions = $CI->survey_model->select_survey_questions($surveyID);
        
        foreach($surveyQuestions as $surveyQuestion){
                
            //Get the survey question title and type
            $question = $CI->question_model->select_question_details($surveyQuestion->questionID);
            
            //Get the survey answer options
            $questionAnswers = $CI->question_model->select_question_options($question->questionID);
            
            
            //Check if its a required question and build the title
            if($surveyQuestion->questionRequired){
                $questionTitle = "<label class='required-question'>" .$question->questionTitle ."*</label>\n";  
            }else{
                $questionTitle = "<label>" .$question->questionTitle ."</label>\n";
            }
                        
            switch($question->type){
                case "TEXT":
                    //Textarea
                    
                    $survey_questions .= "<div class='form-item'>\n";
                    $survey_questions .= $questionTitle;
                    $data = array(
                        'name'        => $question->questionID,
                        'value'        => set_value($question->questionID)
                    );
                    $survey_questions .= form_textarea($data);
                break;
                
                case "SHORT":
                    //Short Answer Questions
                    $survey_questions .= "<div class='form-item text'>\n";
                    $survey_questions .= $questionTitle;  
                    $data = array(
                        'name'    => $question->questionID,
                        'value'    => set_value($question->questionID)
                    );
                    $survey_questions .= form_input($data);
                break;
                
                case "DROPDOWN":
                    //Drop Down Menus
                    $survey_questions .= "<div class='form-item'>\n";
                    $survey_questions .= $questionTitle;
                    foreach($questionAnswers as $questionAnswer){
                        $options[$questionAnswer->answer_value] = $questionAnswer->answer_title;
                    }
                    $survey_questions .= form_dropdown($question->questionID, $options, set_radio("$question->questionID"));
                break;
                
                case "MULTIPLE":
                     //Radio Buttons
                    $survey_questions .= "<div class='form-item radio'>\n";
                    $survey_questions .= $questionTitle;  
                    
                    foreach($questionAnswers as $questionAnswer){
                    
                        $data = array(
                            'name'        => $question->questionID,
                            'value'        => $questionAnswer->answer_value
                        );
                        $survey_questions .= form_radio($data) ."<span>" .$questionAnswer->answer_title ."</span>\n";
                    }
                break;
                
                case "LABEL":
                    //Section Labels
                    $survey_questions .= "<div class='form-item'>\n";
                    $survey_questions .= "<h2>" .$question->questionTitle ."</h2>";
                break;
            }    
        
            $survey_questions .= "</div>\n"; // .form-item
            
        }
        
        return $survey_questions;
    
    } //build_survey_questions

The validation works fine it forces the user to fill out the appropriate fields. My main problem is the validation is not returning the values that the user inputted. And with some surveys that are 30 questions long it would get pretty annoying to re enter your answers.


Messages In This Thread
Problem using Form Validation library - by El Forum - 10-18-2008, 08:18 AM
Problem using Form Validation library - by El Forum - 10-18-2008, 08:54 AM
Problem using Form Validation library - by El Forum - 06-30-2009, 02:20 PM
Problem using Form Validation library - by El Forum - 07-01-2009, 01:19 AM
Problem using Form Validation library - by El Forum - 07-01-2009, 03:49 AM
Problem using Form Validation library - by El Forum - 07-01-2009, 04:16 AM
Problem using Form Validation library - by El Forum - 07-01-2009, 04:26 AM
Problem using Form Validation library - by El Forum - 07-01-2009, 06:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB