Welcome Guest, Not a member yet? Register   Sign In
clear the fields after a post
#1

[eluser]Unknown[/eluser]
I did it in a normal view and use a include to add in the news page

Code:
<div id="comments">

&lt;?php

if($_POST)
{
  $data['idNews'] = $this->uri->segment(3);
  $data['dateHour'] = date('Y-m-d H:i:s');
  $data['name'] = $this->input->post('name');
  $data['email'] = $this->input->post('email');
  $data['comment'] = $this->input->post('comment');
  $data['ip'] = $this->input->ip_address();
  $data['status'] = 0;
  
  if($this->comments_model->add($data))
  {
   echo '<p> Comment add successfully!</p>';
  }
}

?&gt;

&lt;?php

echo form_open(current_url());
  
  echo form_label('Name: ','name');
  echo br();
  echo form_input('name',set_value('name');
  echo br(2);
  echo form_label('Email: ','email');
  echo br();
  echo form_input('email',set_value('email'));
  echo br(2);
  echo form_label('Comment: ','comment');
  echo br();
  echo form_textarea('comment',set_value('comment'));
  echo br(2);
  echo form_submit('mysubmit','Comment');

echo form_close();

?&gt;

&lt;?php

$this->db->order_by('id','asc');
$this->db->where('status',1);
$this->db->where('idNews',$this->uri->segment(3));
$query = $this->db->get('comments');

echo "<hr />";

if($query->num_rows() > 0)
{
foreach($query->result() as $item)
{
  ?&gt;
        
        <div class="coment">
         <a href="mailto:&lt;?php echo $item-&gt;email; ?&gt;">&lt;?php echo $item->name; ?&gt;</a><br />
            <span>&lt;?php echo strftime('Posted %d/%m/%Y as %Hh%M', strtotime($item->dateHour)); ?&gt;</span><br />
            &lt;?php echo $item->comment; ?&gt;
        </div>
        <hr />
        
        &lt;?php
}
}

?&gt;

</div>

The code is working well, but when occours the post, it returns the fields with the data, I need this data disappears when occours the post.

THANKS




Theme © iAndrew 2016 - Forum software by © MyBB