Mostafa Talebi
Mostafa Talebi

Reputation: 9183

Codeigniter From Validation Fails

I have set a form+validation in Codeigniter, but it keeps sending me error though it should not.

I have told the controller (which is responsible to operate the submission) to check for the input, if it is empty send user back to the page with 'fail' word as a URI segment, otherwise, append a 'done' segment to the URI. But it constantly fails and append 'fail' to the URI.

I have checked everything regarding libraries and helpers loading. All are done accordingly.

Here is the HTML:

<form action="<?php echo base_url("category/add"); ?>"  method="post">
<input class="form-input" value="" name="title" placeholder="عنوان دسته" /><br />
<input class="form-submit" name="category-add" value="افزودن" type='submit'/>
</form>

Contoller:

class Category extends CI_Controller
{
    function add ()
    {       
        $this->form_validation->set_rules("title", "Title", "required");


        if($this->form_validation->run == FALSE)
        {                   
            redirect( base_url("page/category/add/fail") );
        }
        else
        {
            redirect( base_url("page/category/add/done") );
        }




    }
}

PROBLEM: the form constantly keeps appending 'fail' to the URI which, as I had set, means the form is not validated.

Thanks in advance

Upvotes: 1

Views: 1689

Answers (1)

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35973

Have you loaded library form_validation?

try something like this:

$this->load->library('form_validation');
$this->form_validation->set_rules("title", "Title", "required");

if ($this->form_validation->run() !== FALSE){
{                   
    redirect( base_url("page/category/add/done") );  
}
else
{
  redirect( base_url("page/category/add/fail") );
}

Upvotes: 2

Related Questions