php, codeigniter
form validation(폼 유효성 검사)
디츠
2014. 10. 13. 23:15
* 컨트롤러
$this->load->library('form_validation');
$this->form_validation->set_rules('title', '제목', 'required'); // 필드 검사
$this->form_validation->set_rules('description', '본문', 'required'); // 필드 검사
- required : 필수
- min_length[5] : 최소 5자
- max_length[10] : 최대 10자
- matches[re_password] : password 필드와 매칭
- valid_email : 메일주소 유효성
- is_unique[user.email] : user 테이블의 email 필드중에 중복값 검색
if ($this->form_validation->run() == FALSE) {
$this->load->view('add');
} else {
$topic_id = $this->topic_model->add($this->input->post('title'), $this->input->post('description'));
}
* 뷰
<?php echo validation_errors(); ?>
출처 : http://opentutorials.org/course/697/3835