CodeIgniter Forums
unvalidated submit - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: unvalidated submit (/thread-45540.html)



unvalidated submit - El Forum - 09-26-2011

[eluser]Unknown[/eluser]
Good morning. The following code works but refreshing browser or submitting an invalid entry still places entry in database. Why, please?
Also the +.50 only displays as +.5 .
Many thanks. Steve.

View index.php
Code:
<div>&lt;?php $inc=0.50;
$total=$num_rows+$inc;?&gt;
    
  Bids so far: &lt;?php echo $num_rows;?&gt;
    
</div>
<div>
&lt;?php foreach ($price as $price): ?&gt;
Your minimum bid:
&lt;?php echo $price['price']+.50;?&gt;
&lt;?php endforeach ?&gt;
&lt;?php echo validation_errors(); ?&gt;

&lt;?php echo form_open('index') ?&gt;

<label for="price">Your bid</label>
&lt;textarea name="price"&gt;&lt;/textarea><br />
&lt;input type="submit" name="submit" value="Place your bid" /&gt;

&lt;/form&gt;

</div>

Controller bids.php
Code:
&lt;?php
class Bids extends CI_Controller {

public function __construct()
{
  parent::__construct();
  $this->load->model('bid_model');
}

public function index()
{
$this->load->helper('form');
$this->load->library('form_validation');

$data['price'] = $this->bid_model->get_bids();

$data['num_rows']= $this->bid_model->get_rows();



$this->form_validation->set_rules('price', 'price', 'required');


if ($this->form_validation->run() === FALSE)
{
  
  $this->load->view('index', $data);

  
}
else
{
  $this->bid_model->place_bid();
  $this->load->view('welcome');
}
}

}

Model Bid_model.php
Code:
&lt;?php
class Bid_model extends CI_Model {



public function get_bids()
{

  $this->db->order_by('price','DESC');
  $this->db->limit('1');
  $query = $this->db->get('bids');
  
  return $query->result_array();
  
    
  }

public function get_rows()
{

  
  $query = $this->db->get('bids');
  $num_rows = $query->num_rows();
  return $num_rows;
  
   }
  
public function place_bid()
{
$this->load->helper('url');

$slug = url_title($this->input->post('price'), 'dash', TRUE);

$data = array(
  
  'price' => $this->input->post('price')
);

return $this->db->insert('bids', $data);
}
}