I found CodeIgniter form validation to show error message with load->view method, and will lost field error message if use "redirect".
Currently I use one function to show form page, and another function to deal form post.
class Users extends CI_Controller { function __construct() { parent::__construct(); } public function sign_up() { $this->load->view('users/sign_up'); } public function do_sign_up(){ $this->form_validation->set_rules('user_login', 'User Name', 'trim|required|is_unique[users.login]'); $this->form_validation->set_rules('user_email', 'Email', 'trim|required|valid_email|is_unique[users.email]'); if ($this->form_validation->run() == FALSE) { $this->load->view('users/sign_up'); }else { // save post user data to users table redirect_to("users/sign_in"); }
When form validation failed, url in browser will changed to "/users/do_sign_up", I want to keep same url in sign_up page.
Use redirect("users/sign_up") method in form validation failed will keep same url, but validation error message will lost.
in Rails, I cant use routes to config like this:
get "users/sign_up" => "users#signup" post "users/sign_up" => "users#do_signup"