custom error message codeigniter doesn't show up

651 Views Asked by At

the custom error message doesn't displaying the error,it only shows blank page instead error message

here is my controller :

public function daftar(){
  $this->form_validation->set_rules('email','Email','required');
  $this->form_validation->set_rules('nama','Nama','required');
  $this->form_validation->set_rules('pass','Password','required');
  $this->form_validation->set_rules('passconf','PasswordConf','required|matches[pass]');

  if($this->form_validation->run()==FALSE){
  $this->form_validation->set_message('passconf','the password doesnt match');

 }
 else{
   redirect('lowongan/daftar_employer');
 }

 }

}

2

There are 2 best solutions below

2
Dan Spiteri On

You need to escape the apostrophe in the word "doesn't".

$this->form_validation->set_message('passconf','the password doesn\'t match');
1
Kanishka Panamaldeniya On

write a custom callback function to set your own error message

callback_custom_error

  $this->form_validation->set_rules('passconf','PasswordConf','required|matches[pass]|callback_custom_error');


public function custom_error($str)
{
    if($this->form_validation->run()==FALSE)
    {
          $this->form_validation->set_message('passconf','your custom message');
          return FALSE;
    }
    else
    {
          return TRUE;
    }

}