Welcome Guest, Not a member yet? Register   Sign In
How to call certain div class when certain condition is done?
#1

[eluser]Michal1[/eluser]
Hello guys,

I have pretty basic and stupid question. How to show certain div class when some condition is done. Let say in my view I have

Code:
<div class="msg msg-ok">
   <p><strong>Your file was uploaded succesifully!</strong></p>
   <a href="#" class="close">close</a>
  </div>

and in my controller i have function which handles adding articles.

Code:
public function add_thread()
{
  
  
  $data = array(
  'name' =>$this->input->post('name'),
  'text'=>$this->input->post('text')
  );
  
  $this->site_model->insert_thread($data);
  
  redirect ('site');
  
}

and after this is done I want to display that msg msg-ok from my view. How to do that please?
#2

[eluser]Michal1[/eluser]
Nobody knows?
#3

[eluser]Silviu[/eluser]
I've noticed that you are using a redirect (presumably, after the form was successfully submitted). You can use a flashdata session variable as a hook for that message:
Code:
public function add_thread()
{
  $data = array(
  'name' =>$this->input->post('name'),
  'text'=>$this->input->post('text')
  );
  $this->site_model->insert_thread($data);
  $this->session->set_flashdata('success',TRUE);
  redirect ('site');
}
Now, in your view, do the following:
Code:
&lt;?if($this->session->flashdata('success')):?&gt;
   <div class="msg msg-ok">
      <p><strong>Your file was uploaded succesifully!</strong></p>
      <a href="#" class="close">close</a>
   </div>
&lt;?endif?&gt;
Since flashdata variables are available only for the next page load, your message will be shown only when your form was successfully submitted.
#4

[eluser]dhiya[/eluser]
Try this solution:

in your view:

&lt;?php if(isset($message)){ ?&gt;
<div class="msg msg-ok">
<p><strong>Your file was uploaded succesifully!</strong></p>
<a href="#" class="close">close</a>
</div>
&lt;?php } ?&gt;

in your controller:

public function add_thread()
{
$data = array(
'name' =>$this->input->post('name'),
'text'=>$this->input->post('text')
);

if($this->site_model->insert_thread($data))
{
$data['message'] = 'your message here';
}

$this->load->view('your_view.php',$data);

redirect ('site');

}
#5

[eluser]Michal1[/eluser]
thank you so much!
#6

[eluser]Michal1[/eluser]
solved




Theme © iAndrew 2016 - Forum software by © MyBB