First, i would to apologize for my bad english.
Suppose i have function in controller like this :
function confirm()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|exist[member.email]');
$this->form_validation->set_rules('secretKey','Secret Key', 'required|callback_secret_check');
$this->form_validation->set_message('exist',"Email don't exist");
$this->form_validation->set_message('secret_check','Invalid confirmation code');
if ($this->form_validation->run() == FALSE)
{
// if error, show form and the error msg
$this->view->full_render('user_confirm') ;
} else {
// if all ok
echo "success" ;
}
}
In short, this function is used to validate new user email using confirmation code. Just like we found in any site that need registration. I made this function in case some user prefer to submit his confirmation code directly using confirmation form instead of using confirmation url (we send both confirmation url and confirmation code to his email)
Just for your information, the rule "exist" is my own rule created by extending the form class to check if the email submitted is really exist. For the "callback_secret_check" rule, i create callback function (not by extending the form validation class like first rule) to check if the confirmation code submitted by the user is a valid one.
Now, suppose i have user email "[email protected]" with confirmation code "12345". If he submit "[email protected]" with code "22323" then the system will show error message:
- invalid confirmation code
No problem with this case.
But, if somebody submit "[email protected]" with any confirmation code, the system will show error message
- Email don't exist
- Invalid confirmation code
what i wanted is only
- Email don't exist
without showing "invalid confirmation code" because if the email did not even exist, i think we don't need to tell anything about the confirmation code. Any clue?
thanks for your help.