title: Codeigniter form on same page as results
body: <p>I am using codeigniter and the tutorial from <a href="http://imsocode.com/?p=285" rel="nofollow">here</a>. I have made a basic blog tool which works fine. However as it stands to add a new post you have to go to a separate page 'create.php' to get to the form. I would like to try and put the form on the same page as the page that will be updated i.e. 'index.php'. If I try to do this at the moment the form simply refreshes and does submit the data.</p>
  
  <p>model</p>
  
  <pre><code>function insert_post($data){
      $this-&gt;db-&gt;insert('posts', $data);
      return;
  }
  </code></pre>
  
  <p>Current View (admin/create.php)</p>
  
  <pre><code>&lt;?php echo validation_errors(); ?&gt;
  
  &lt;h4&gt;Create A New Post Below&lt;/h4&gt;
  &lt;form action="" method="post" &gt;
  &lt;p&gt;Title:&lt;/p&gt;
  &lt;input type="text" name="title" size="50"/&gt;&lt;br/&gt;       
  &lt;p&gt;Summary:&lt;/p&gt;
  &lt;textarea name="summary" rows="2" cols="50"&gt;&lt;/textarea&gt;&lt;br/&gt;
  &lt;p&gt;Post Content:&lt;/p&gt;
  &lt;textarea name="content" rows="6" cols="50"&gt;&lt;/textarea&gt;&lt;br/&gt;
  &lt;input type="submit" value="Save" /&gt;
  
  &lt;?php echo anchor('admin','Cancel'); ?&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>View I would like the form to be on (index.php)</p>
  
  <pre><code>&lt;?php
      echo '&lt;p&gt;Welcome '.$username.'! All posts available for edit or deletion is listed below.&lt;/p&gt;&lt;br/&gt;';
  
      echo anchor('admin/create','Create New Post');
  
      $count = count($post['id']);
      for ($i=0;$i&lt;$count;$i++)
      {
          echo '&lt;div class="postDiv"&gt;';
          echo '&lt;h4&gt;'.$post['title'][$i];
          echo '&lt;p&gt;'.$post['summary'][$i].'&lt;/p&gt;';
          echo '&lt;p&gt;'.$post['content'][$i].'&lt;/p&gt;';
          //echo anchor('blog/view/'.$post['id'][$i],' [view]');
          echo anchor('admin/edit/'.$post['id'][$i],' [edit]');
          echo anchor('admin/delete/'.$post['id'][$i],' [delete]&lt;/h4&gt;');
          echo '&lt;/div&gt;';
      }
  ?&gt;
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>function create(){
      $data['userId'] = $this-&gt;tank_auth-&gt;get_user_id();
      $data['username'] = $this-&gt;tank_auth-&gt;get_username();
  
      $this-&gt;form_validation-&gt;set_rules('title','title','required');
      $this-&gt;form_validation-&gt;set_rules('summary','summary','required');
      $this-&gt;form_validation-&gt;set_rules('content','content','required');
  
      if($this-&gt;form_validation-&gt;run()==FALSE)
      {
          $this-&gt;load-&gt;view('template/admin_html_head',$data);
          $this-&gt;load-&gt;view('admin/create',$data);
          $this-&gt;load-&gt;view('template/html_tail',$data);
      } else {
          $data = $_POST;
          $this-&gt;posts-&gt;insert_post($data);
          redirect('admin');
      }
  }
  </code></pre>
  
  <p>This was straight forward when I used normal php but with codeigniter I am getting lost with the MVC stuff. I know this is probably a fairly basic question so please either explain your answer or give me a link to something which will explain what I need to do as I want to learn from this. I have read the codeigniter docs on validation but I dont think thats my problem?</p>