Crazy with callbacks |
I'm going crazy,
I think I did everything correctly, because I took the code of another example of my project and everything works properly them. Controller: PHP Code: public function title_check_exist($title) { Model: PHP Code: public function title_check($title) { When I insert a title or a link already exists in the database, it is not calculated but also created the page. All other rules instead are read properly and when something deliberately wrong in the callback is signaled. What is the error that I can not find? Thanks for your continued support that you give me. EDIT: I can try edit this part PHP Code: if ($query->num_rows() > 0){ with this code: PHP Code: if ($title = 'title of page'){ and the result it is the same.
Ok, I'm stupid ahah
with the is_unique rules I can solve this problem peacefully. I would really like to know why this method does not work
You set the error message when the condition is FALSE, not true. True means it passed the rule, so no error message. Your rule is probably working but you probably just aren't seeing the error message.
I also tried to move the message after the else.
But if even so if I write the same values as the page is created. In db sprouting 2 equal voices.
Your callback:
callback_title_check_exist Your function name: title_check (should be title_check_exist) Also, you want to set the error message BEFORE returning false in the callback.
I show you the code of the other case. I seeing that this solved is_unique.
Model: PHP Code: public function username_check($username) { Controller: PHP Code: public function username_check_exist($username) { In this case I can try to stamp the $query->num_rows() and the result is 1 in the page... but It does not show the error code. And if I fill out all the fields also launches the query.
public function username_check($username) {
... $this->form_validation->set_message('username_check_exist', 'L´username è già utilizzato.'); Your message name needs to match the rule (function) name. Rule name is "username_check", so message also must be "username_check" and not "username_check_exist"
(06-10-2015, 06:49 AM)CroNiX Wrote: public function username_check($username) { But in the controller my rules is PHP Code: public function username_check_exist($username) { for this reason in the callback I can use callback_sername_check_exist But at this point, even if it does not show me the error message, you should at least stop sending the query, no?
I think it's because you're setting the error message OUTSIDE of where the actual validation rule (username_check_exist) is defined.
In your auth: PHP Code: public function username_check($username) { In your controller: PHP Code: public function username_check_exist($username) {
(06-10-2015, 07:01 AM)CroNiX Wrote: I think it's because you're setting the error message OUTSIDE of where the actual validation rule (username_check_exist) is defined. I change the auth and controller with your code, meanwhile, I thank you for your time that you're offering me And now I can tell you that is not working. It does not display the error and still launches the query As absurd thing. All other rules of the same field are used properly |
Welcome Guest, Not a member yet? Register Sign In |