2012-02-03 5 views
3

CodeIgniter 폼 유효성 검사 클래스를 사용하려고합니다. 아래 코드에서 볼 수 있듯이 "valid_email"매개 변수를 사용했지만 올바르지 않은 전자 메일 주소를 입력해도 유효성 검사를 통과합니다. 나는 문자열 테스트 : testing123CodeIgniter 폼 유효성 검사 valid_email이 작동하지 않습니다.

public function login() 
{ 
    $this->form_validation->set_rules('authEmail', 'trim|required|valid_email|xss_clean'); 
    $this->form_validation->set_rules('authPassword', 'trim|required'); 

    $email = $this->input->post('authEmail'); 
    $password = $this->input->post('authPassword'); 

    if($this->form_validation->run() === FALSE) { 
     $this->session->set_flashdata('formValidationError', validation_errors('<p class="error">', '</p>')); 
     redirect('/'); 
    } else { 
     // Begin authentication 
    } 
} 

사람은 내가 잘못 어떤 생각을 가지고 또는 이것은 CodeIgniter의 문제의 경우? 사용에 반대

가 나는 flashdata 세션을 설정하고, 참고 :이 개인의 나는 로그인 페이지 인 (홈페이지로 다시 리디렉션을 수행하고 있기 때문에

<?php echo validation_errors(); ?> 

을 ...이있다 대지).

답변

6

http://codeigniter.com/user_guide/libraries/form_validation.html#validationrules에서이 시도 :

public function login() 
{ 
    $this->load->library('form_validation'); 

    $this->form_validation->set_rules('authEmail', 'Email', 'trim|required|valid_email|xss_clean'); 
    $this->form_validation->set_rules('authPassword', 'Password', 'trim|required'); 

    if($this->form_validation->run() !== false){ 
    //validation passed 
    $email = $this->input->post('authEmail'); 
    $password = $this->input->post('authPassword'); 
    // Begin authentication 
    } 
    else { 
     $this->session->set_flashdata('formValidationError', validation_errors('<p class="error">', '</p>')); 
     redirect('/'); 
    } 
} 
+2

내가 문제와 답의 다른 유효성 검사 규칙은 무엇 이해할 수 없다? – KTAnj

1

난 그냥 사용하는 법을 배우고 있지만 세 가지 매개 변수가 필요하지 않습니까? 이것은 그들의 양식 유효성 검사 페이지에서입니다 :

$this->form_validation->set_rules('email', 'Email', 'required'); 

The field name - the exact name you've given the form field. 

A "human" name for this field, which will be inserted into the error message. For example, if your field is named "user" you might give it a human name of "Username". Note: If you would like the field name to be stored in a language file, please see Translating Field Names. 

The validation rules for this form field. 
관련 문제