| 제목 | form_validation 관련 질문좀 여쭤볼게요. | ||
|---|---|---|---|
| 카테고리 | CI 2, 3 | ||
| 글쓴이 | 기브미 | 작성시각 | 2017/08/23 14:27:31 | 
| 
                         | 
                |||
| 
                         회원가입페이지에서 입력롼효 회원가입처리 부분을 컨트롤러에서 처리중입니다. 
 이미 해당 디비 테이블에 등록된 userid로 테스트중인데요. 
 $this->form_validation->set_rules("userid", "아이디", "required|xss_clean|min_length[4]|max_length[14]|callback_userid_duplicate_check"); 로 CI에 기본지원하는 required|xss_clean|min_length[4]|max_length[14] 를 사용하였고요. 호출되도록 하였는데요. public function userid_duplicate_check(){ $userid = $this->input->post("userid", true); $this->db->select("userid"); $this->db->where("userid", $userid); $query = $this->db->get("da_member"); $userid_chk = $query->row(); if(isset($userid_chk->userid)) { $this->form_validation->set_message("userid_duplicate_check", "이미 등록된 회원아이디입니다."); } } 
 분명히 userid 를 print_r로 찍어보면 값이 있는데요. 
 if(!$this->form_validation->run()){ $err = $this->form_validation->error_array(); if(count($err) > 0) { $keys = array_keys($err); $error = $err[$keys[0]]; msg($error); exit; } } msg에서 "이미 등록된 회원아이디입니다."가 아닌 "아이디은(는) 필수입니다." 라고 뜨네요. is_unique가 있지만 CI 전체에서 공통적으로 돌아가는부분이라 error메시지를 회원만 따로 처리하기가 애매하고 회원가입페이지에서 id중복체크도 겸으로 같이 사용가능하여 저렇게 callback을 붙어서 처리하였는데요. 
 
 system 파일에 form_validation helper를 까보니 function _execute쪽에 
 // If we get an array field, but it's not expected - then it is most likely // somebody messing with the form on the client side, so we'll just consider // it an empty field $postdata = is_array($this->_field_data[$row['field']]['postdata']) ? NULL : $this->_field_data[$row['field']]['postdata']; 이부분에서 required 에서 postdata가 빈값으로 잡혀있네요.. 
 
 
  | 
                |||
| 다음글 | .php 를 url로 연결 (1) | ||
| 이전글 | 질문.. (4) | ||
| 
                             
                                기브미
                                /
                                2017/08/23 15:32:12 /
                                추천
                                0
                             
                             | 
                    
해답을 찾았습니다.
callback 함수에 return값이 없어서 정상적으로 동작이 안되었네요.
return true, false를 처리하니 정상적으로 작동됩니다.