Codeigniter validation errors

10,528

The problem was in the class error with attribute display:none

Share:
10,528
Alessandro Minoccheri
Author by

Alessandro Minoccheri

I love what I code!!! https://github.com/AlessandroMinoccheri

Updated on June 04, 2022

Comments

  • Alessandro Minoccheri
    Alessandro Minoccheri almost 2 years

    I have a site develop in codeigniter. I want to validate a form and display some message. With my code I don't see any error if my input "name_it" is blank. Why? This is my controller:

    public function nation_create()
        {
            if($_POST)
            {
                //salvo i dati
                $this->load->library('form_validation');
                $this->form_validation->set_error_delimiters('<p class="error">Errore: ', '</p>');
                $this->form_validation->set_rules('name_it', 'name_it', 'required');
                if ($this->form_validation->run() !== FALSE){
                    $this->Nation_model->createNation();
                    redirect('backend/nation/nation_list/');
                }
                else{
                    $data['errors'] = validation_errors();
                    $this->load->view('backend/include/header_view_logged');
                    $this->load->view('backend/nation_create_view',$data);  
                    $this->load->view('backend/include/footer_view');
                }
            }
            else{
                $this->load->view('backend/include/header_view_logged');
                $this->load->view('backend/nation_create_view');    
                $this->load->view('backend/include/footer_view');
            }
        }
    

    And this is my view (I have cut more code to read well)

    <form action='' method='POST'>
       <?php echo validation_errors(); 
       if (isset($errors))
          echo $errors;
       ?>
       <?php echo form_error('name_it'); ?>
       <input type="text" name="name_it" />
       <span id="errorsDiv_name_it"></span>
    </form>
    
  • Alessandro Minoccheri
    Alessandro Minoccheri about 11 years
    Is the same control! Is the same thing that I have already done, you have only change !== FALSE isn't that the problem
  • tomexsans
    tomexsans about 11 years
    what i am telling you is the if($_POST) and $this->form_validation()->run() is the same you are having redundant code