0

codeIgniter validation error not displaying errors when validation fails, i have tried var_dumping the validation_errors() and form_error() function. This is annoying because i have used form_validation in 6 CI projects.

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 Answer 1

1

I figured out my bug, in my config file, i autoloaded form_Validation instead of "form_validation" with a small later v. Banging my head against the wall

Sign up to request clarification or add additional context in comments.

1 Comment

Dont sweat it. I once worked on a problem for 3 days before I realized I was using $ajax instead of $.ajax

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.