CodeIgniter Forums
Validation and view page problem. - 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: Validation and view page problem. (/showthread.php?tid=46653)



Validation and view page problem. - El Forum - 11-09-2011

[eluser]Unknown[/eluser]
Hi,

I had some question about validation.


URL: /ItemDetail/5
ItemDetail is the Controller Name
5 is the Item ID

at this page, visitor can post a price and submit to the website, so I need to do a validation for the Price field.

Code:
<?=form_open('ItemDetail/validatebid'); ?>
         <?=form_hidden('Jid',$this->uri->segment(3))?>
          <center>&lt;?=form_error('price')?&gt;</center><br>
         <center>price&lt;input name="price" type="text" value="&lt;?=set_value('price')?&gt;"&gt;&lt;br>
&lt;?=form_button(array('name' => 'submit', 'type' => 'submit', 'class' => 'btn_post'))?&gt;</center>
    &lt;/form&gt;

In this form, I create a function name ItemDetail/validatebid for the validate:

Code:
$this->form_validation->set_rules('price', 'price', 'trim|numeric|max_length[6]');

  if ($this->form_validation->run() == FALSE)
  {
   $this->load->view('itemdetail', $data);
  }
  else
  {
   $this->load->model('data_model');
   $this->data_model->insert_bid();
   redirect('itemdetail/'.$this->uri->segment(2));
  }

problem occur: when user input pass the submit button, it will go to ItemDetail/validatebid for validation, at that time, the Item ID didn't contain the Item ID in segment(2), I can't display proper Item Information. How can I fix this problem?