• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to set segment to view in codeigniter after form validation fails?

#2
[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

As soon as you redirect, the $_POST data is not submitted to the server, and this you lose your error messages. You shouldn't redirect until after validation has passed.

Your execution flow should be something like this:

Code:
function item($id = 0)
{
// You should also check that the item exists, and react accordingly if it doesn't.
$data['things'] = $this->listings_model->get_item($id);

// Load the form validation library.
$this->load->library('form_validation');

// Set the rules.
$this->form_validation->set_rules('captcha', 'Captcha', 'required|trim|callback_check_captcha' )

// Attempt to run validation.
if (true === $this->form_validation->run()) {
  // Save to the database and redirect.
  $this->listings_model->update_listing();
  redirect('wherever');
}

// Load the view. This will be displayed when the controller is first called,
// and when validation fails.
$this->load->view('list/item_view', $data);
}

I know that the above doesn't fit in to how you're doing things, but hopefully it'll help get you started.


Messages In This Thread
How to set segment to view in codeigniter after form validation fails? - by El Forum - 03-23-2013, 03:34 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.