RedPetals
RedPetals

Reputation: 81

Codeigniter Custom data validation

I will try to upload an Excel file and verify its contents.

So I tried the code as below.

if ($this->upload->do_upload("filename"))
{

    ...

    // I Think it is idiot code . . but . . anyway . . :_(
    $_POST = array(
        "name" => $cell[0],
        "phone" => $cell[1],
        "birth" => $cell[2],
        ...
    );


    $config = array(
        array("field"=>"name", "label"=>"Name", "rule"=> "required"),
        ...
    );

    $this->form_validation->set_rules($config);
    $this->form_validation->set_error_delimiters('', '');

    if ($this->form_validation->run() === false)
    {
        throw new Exception($this->form_validation->error_string());
    }

    ...
}

How to validate custom data using form_validation?

Upvotes: 0

Views: 564

Answers (1)

Medivh
Medivh

Reputation: 11

You can pass your data like that:

$data = array(
'username' => 'johndoe',
'password' => 'mypassword',
'passconf' => 'mypassword'
);

$this->form_validation->set_data($data);

Upvotes: 1

Related Questions