CI 묻고 답하기

제목 [초보]폼검증의 예외의 경우
글쓴이 헛발이 작성시각 2010/01/18 14:29:42
댓글 : 4 추천 : 0 스크랩 : 0 조회수 : 26420   RSS
폼검증에 보면 숫자를 넣었나.. 영문을 넣었나 하는 Rule Reference 이 있잖아요?
그것 이외에 자신만의 특정 검증을 하길 원하다면 어떤 식으로 만들어 사용해야 하는지 궁굼하네요..

현재 하려고자 하는것이 입력받은 값이 날짜포멧인지 확인 하려는데요..0000-00-00 이런 포멧인지 확인 하려는데..
$this->form_validation->set_rules('request_date', '날짜', 'trim|required|xss_clean');
이곳에 함꼐 사용할 순 없는것인지요?
 다음글 [초보]modular_separation_17에 관하여 (8)
 이전글 [초보]저도 matchbox에 관한 질문 (4)

댓글

변종원(웅파) / 2010/01/18 14:45:43 / 추천 0
그런 경우에는 콜백 기능을 사용하셔야 합니다.

http://codeigniter-kr.org/user_guide/libraries/form_validation.html#callbacks

값이 입력되었다면 해당 콜백함수를 호출하여 처리하시면 됩니다.
아래 내용중 9번째 라인 callback_username_check 와 24번째 라인 username_check() 함수 참고

class Form extends Controller {
	
	function index()
	{
		$this->load->helper(array('form', 'url'));
		
		$this->load->library('form_validation');
			
		$this->form_validation->set_rules('username', 'Username', 'callback_username_check');
		$this->form_validation->set_rules('password', 'Password', 'required');
		$this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
		$this->form_validation->set_rules('email', 'Email', 'required');
					
		if ($this->form_validation->run() == FALSE)
		{
			$this->load->view('myform');
		}
		else
		{
			$this->load->view('formsuccess');
		}
	}
	
	function username_check($str)
	{
		if ($str == 'test')
		{
			$this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	}
	
}

헛발이 / 2010/01/18 14:50:28 / 추천 0
아 이런게 다 있었군요 ㅋㅋ
또 감사드립니다..
케이든 / 2010/01/18 16:21:13 / 추천 0
폼_벨리데이션 라이브러리를 확장하셔도 됩니다

http://net.tutsplus.com/tutorials/php/6-codeigniter-hacks-for-the-masters/

예제로 링크 3번째 핵 참조해보세요
byung82 / 2010/02/03 23:19:11 / 추천 0
 CI_Form_Validation을 확장하셔서 쓰셔도 됩니다