jayz jayz - 8 months ago 96
PHP Question

Codeigniter form validation error messages with bootstrap

I am new to

php codeigniter
framework. I am using basic form submission to submit data through a form. There is a form validation error showing function in
codeigniter framework
What I want to do is, when there is an error show it an a bootstrap popup or warning message. I tried so many ways but did not succeed. When I used bootstrap warning messages, I was unable to hide it when there was no error and in page load.
Can someone please help me with this.


in codeigniter when you'r form is submitted , you can validation form elements like this :

$this->form_validation->set_rules('your element', ' ', 'trim|required');
if ($this->form_validation->run() == FALSE) 
   $this->session->set_flashdata('message', 'Yor're data is not valid!');

and you can use up session in view for bootstrap alert like this :

<div style="margin-top: 8px" id="message">
           if($this->session->userdata('message') != null)
               echo '<div class="alert alert-success" role="alert">';
               echo '<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>';
               echo $this->session->userdata('message') <> '' ? $this->session->userdata('message') : '';
               echo '</div>';