2012-02-03 14 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

私はそれを使うことを学んでいますが、3つのパラメータは必要ありませんか?これは、自分のフォームの検証ページからです:

$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. 
関連する問題