Form validation error message issues - El Forum - 10-11-2012
[eluser]RalphLeMouf[/eluser]
I'm really close but the errors I tried to add via Code: echo validation_error();
is not correct. So should I make that from scratch or is there a code-igniter shortcut for that?
This is what I ended up with:
Code: function validate_credentials_login()
{
$this->load->library('session');
$this->load->helper(array('form','url'));
$this->load->model('user_model', 'um');
$this->load->library('encrypt');
$this->load->library('form_validation');
$this->form_validation->set_rules('email_login', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password_login', 'Password', 'trim|required');
if ( $this->form_validation->run() === TRUE )
{
$user = $this->um->validate_home_login(array('email' => $this->input->post('email_login')));
if ( $user )
{
if ( $user->password == $this->encrypt->sha1( $user->salt . $this->encrypt->sha1($this->input->post('password_login'))) && $user->email == $this->input->post('email_login') )
{
$this->session->set_userdata(array('email' => $this->input->post('email_login')));
redirect('account/edit');
}
else
{
echo validation_error();
}
}
else
{
echo validation_error();
}
}
Form validation error message issues - El Forum - 10-15-2012
[eluser]ojcarga[/eluser]
I meant you can do something like this:
Code: function validate_credentials_login()
{
$this->load->library('session');
$this->load->helper(array('form','url'));
$this->load->model('user_model', 'um');
$this->load->library('encrypt');
$this->load->library('form_validation');
$this->form_validation->set_rules('email_login', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password_login', 'Password', 'trim|required');
if ( $this->form_validation->run() === TRUE )
{
$user = $this->um->validate_home_login(array('email' => $this->input->post('email_login')));
if ( $user )
{
if ( $user->password == $this->encrypt->sha1( $user->salt . $this->encrypt->sha1($this->input->post('password_login'))) && $user->email == $this->input->post('email_login') )
{
$this->session->set_userdata(array('email' => $this->input->post('email_login')));
redirect('account/edit');
}
else
{
$data["my_custom_error"] = "Password you entered and the one in the DB donĀ“t match!!";
}
}
else
{
$data["my_custom_error"] = "NO $user, validation of validate_home_login failed.";
}
}
$data['main_content'] = 'home/home_page';
$this->load->view('includes/templates/home_page_template', $data);
}
OR, maybe you want to use the form validation library, under "Setting Error Messages" subtitle you have the way to achieve that:
http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#settingerrors
Cheers!
|