I found a CodeIgniter form check to show an error message with the load-> view method, and the field error message will be lost if you use "redirection".
I am currently using one function to display a form page and another function to send a form message.
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");
}
If the form validation fails, the URL in the browser will change to "/ users / do_sign_up", I want to keep the same URL on the sign_up page.
Using the redirect method ("users / sign_up") as a result of an unsuccessful form validation will support the same URL, but the validation error message will be lost.
in Rails, I cannot use routes for configuration as follows:
get "users / sign_up" => "users # signup"
post "users/sign_up" => "users#do_signup"