验证失败时,codeIgniter form_error()不显示错误

时间:2017-03-29 06:27:34

标签: php codeigniter validation

codeIgniter验证错误在验证失败时没有显示错误,我已经尝试了var_dumping validation_errors()和form_error()函数。这很烦人,因为我在6个CI项目中使用了form_validation。



public function create(){	
    $error = '';
    $this->form_validation->set_rules('username','Username','trim|required');
  $this->form_validation->set_rules('email','Email','trim|required|valid_email');
    $this->form_validation->set_rules('password','Password','trim|required');
		$this->form_validation->set_rules('passwordConfirm','Confirm Password','trim|matches[password]');
		$this->form_validation->set_rules('phone','Phone','trim|required');
		$this->form_validation->set_rules('bank_name','Bank name','trim|required');
		$this->form_validation->set_rules('bank_acc_name','Account name','trim|required');
		$this->form_validation->set_rules('bank_acc_no','Account no','trim|required');
		
		if($this->form_validation->run() === TRUE){
			
			$response = $this->user_model->create_user();
		}
		
		if(count($this->form_validation->error_array()) > 0){
			$error = 'Check input provided';
			var_dump(validation_errors()); die();
		}
		
		$data = [
			'error'=>$error,
			'form'=>[
				'username'=>[
					'value'=>  set_value('username'),
					'error'=>  form_error('username')
				],
				'email'=>[
					'error'=>  form_error('email'),
					'value'=>  set_value('email')
				],
				'password'=>[
					'error'=>  form_error('password'),
					'value'=>  set_value('password')
				],
				'passwordConfirm'=>[
					'error'=>  form_error('passwordConfirm'),
					'value'=>  set_value('passwordConfirm')
				],
				'phone'=>[
					'error'=>  form_error('phone'),
					'value'=>  set_value('phone')
				],
				'bank_name'=>[
					'error'=>  form_error('bank_name'),
					'value'=>  set_value('bank_name')
				],
				'bank_acc_name'=>[
					'error'=>  form_error('bank_acc_name'),
					'value'=>  set_value('bank_acc_name')
				],
				'bank_acc_no'=>[
					'error'=>  form_error('bank_acc_no'),
					'value'=>  set_value('bank_acc_no')
				]
				
			]
		];
		//var_dump($data); die();
		$this->load->view('header');
		$this->load->view('register',['data'=> json_decode(json_encode($data),FALSE)]);
		$this->load->view('footer');
	}




1 个答案:

答案 0 :(得分:1)

我弄清楚了我的错误,在我的配置文件中,我自动加载了form_Validation而不是" form_validation"稍后一点v。把头靠在墙上