Welcome Guest, Not a member yet? Register   Sign In
[CI_NOVICE_HELP] Setting Custom Error Message
#1

[eluser]Andy Armstrong[/eluser]
I really want to create a custom message with all set rules with "required" rule. This is my sample code, creating a call back function is what i want for my script however i am having problems displaying the custom error on the page, i am just a novice for this new framework, I hope you CI geek guys could help me it would be great and i am honored to belong with this friendly CI community. Thank you very much..


public function addnew(){


$this->form_validation->set_rules('fullname','Full Name','trim|required');
$this->form_validation->set_rules('phonenumber','Phone Number','trim|required');
$this->form_validation->set_rules('age','Age','trim|required|numeric');
$this->form_validation->set_rules('address','Address','trim|required');
$this->form_validation->set_rules('email','Email','trim|required|valid_email|is_unique[phonebook.email]');

if($this->form_validation->run() == FALSE){

//Supposed to be my custom error message for all set_rule that has a "required" rule
$this->form_validation->set_message('required','important!');
$this->load->view('addnewcontacts');
}
else
{
$fullname = $this->input->post('fullname');
$phonenumber = $this->input->post('phonenumber');
$age = $this->input->post('age');
$address = $this->input->post('address');
$email = $this->input->post('email');

$this->phonebook->insert_phonebook($fullname,$phonenumber,$age,$address,$email);

}
}

//I want to set a call back function to be called by email checking if the user has a unique email
private function error_email(){

if($this->form_validation->set_rules('email','Email','trim|required|valid_email|is_unique[phonebook.email]')):
$this->set_message('error_email','This email is already taken');
endif;
}




Theme © iAndrew 2016 - Forum software by © MyBB