1

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

1 Answer 1

2

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") );
}
Sign up to request clarification or add additional context in comments.

4 Comments

load helper and library $this->load->helper(array('form', 'url')); $this->load->library('form_validation');
aleays going to fail? Try to remove value="" from the input @MostafaTalebi
it is OK now! using your recommendation I reversed the conditional and now it is all OK.....thanks
by using redirect() you do not able to show validation messages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.