CodeIgniter Forums
How to call certain div class when certain condition is done? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to call certain div class when certain condition is done? (/showthread.php?tid=51036)



How to call certain div class when certain condition is done? - El Forum - 04-18-2012

[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?


How to call certain div class when certain condition is done? - El Forum - 04-19-2012

[eluser]Michal1[/eluser]
Nobody knows?


How to call certain div class when certain condition is done? - El Forum - 04-19-2012

[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.


How to call certain div class when certain condition is done? - El Forum - 04-19-2012

[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');

}


How to call certain div class when certain condition is done? - El Forum - 04-19-2012

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


How to call certain div class when certain condition is done? - El Forum - 04-19-2012

[eluser]Michal1[/eluser]
solved