Welcome Guest, Not a member yet? Register   Sign In
Unable to find validation rules when using $this->form_validation->set_rules
#1

I can't figure out why I'm getting the error "Unable to find validation rules" when I set the rules in the controller using $this->form_validation->set_rules.
Here is my JS code: 
Code:
            var id = $('#pkStudyYears').val();
            var data = {};
           
            data['pkStudyYears'] = id;
            data['years']={};
            data['years']['pkStudyYears']=id;
            data['years']['fkStudyID'] = $('#fkStudyID').val(); 
            data['action'] = action;

            data['years']['intStartYr']= $('#startYearBox').val();
            data['years']['intEndYr']= $('#endYearBox').val();
           
            var posturl = '<?php echo site_url('manage/climate_indicators/updateStudyYears');?>'
         
    $.when($.ajax({type: "POST", url: posturl, data:data, dataType: 'json'})).done(function(result) {
                console.log(result.status);
});

And php:
PHP Code:
  public function updateStudyYears() {
        
        
if (!$this->input->post() OR !$this->input->is_ajax_request() ){
            echo json_encode(array('status'=>'failed','errors'=>array('Access Mode'=>'Disallowed')));
            exit();
        }
        else {
            $postData $this->input->post(NULLtrue);
            
            $yearArray 
$postData['years'];
            
            
if(empty($yearArray)) {
                echo json_encode(array('status'=>'failed''errors'=>'Years are empty'));
                exit();
            }    
            $this
->form_validation->set_rules('years[intStartYr]''Start Year''required',
                    array('required' => 'Start year must have a valid year.'));
            $this->form_validation->set_rules('years[intEndYr]''End Year''required',
                    array('required' => 'End year must have a valid year.'));
            
            
if ($this->form_validation->run() === FALSE) {  
                $validationErrs 
$this->form_validation->error_array();
            
                
echo json_encode(array('status'=>'form-errors''valErrs'=>$validationErrs));                
                
exit;
            }
            else {                        
                $status 
$this->climate_indicators_model->setStudyYears($yearArray);            
                
if ($status) {
                    echo json_encode(array('status'=>'success''message'=>'Study year information successfully updated.'));                    
                
}
                else echo json_encode(array('status'=>'failed''errors'=>'Db error on update'));
            }
            exit();
        }
    }    


Thank you!
Reply


Messages In This Thread
Unable to find validation rules when using $this->form_validation->set_rules - by xanabobana - 10-20-2021, 09:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB