Reputation: 401
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.
Upvotes: 0
Views: 2329
Reputation: 1514
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">
<?php
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">×</a>';
echo $this->session->userdata('message') <> '' ? $this->session->userdata('message') : '';
echo '</div>';
}
?>
</div>
Upvotes: 3
Reputation: 1327
Use flashdata
to show your error messages
$this->session->set_flashdata('flashSuccess', 'Leave Applied successfully');
$this->session->set_flashdata('flashError', 'Some error found');
In your header add some code to display flash data
<div class="container">
<div class="row" id="flashMessage">
<?php
if ($this->session->flashdata('flashError')) {
?>
<br/>
<div class="alert alert-danger alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<h4>Error!</h4>
<p><?php echo $this->session->flashdata('flashError'); ?>.</p>
</div>
<?php
}
if ($this->session->flashdata('flashSuccess')) {
?>
<br/>
<div class="alert alert-success alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<h4>Success!</h4>
<p><?php echo $this->session->flashdata('flashSuccess'); ?>.</p>
</div>
<?php
}
?>
</div>
</div>
Upvotes: 3