CodeIgniter Forums
Crazy with callbacks - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Crazy with callbacks (/showthread.php?tid=62106)

Pages: 1 2


RE: Crazy with callbacks - CroNiX - 06-10-2015

oh, instead of this in the auth::username_check():
return ($query->num_rows() > 0);

You probably need:
return ($query->num_rows() == 0);

because if there were NO results, it means the username was NOT taken and the rule should pass (true). It should fail (false) if there are any results because the username already exists.


RE: Crazy with callbacks - StratoKyke - 06-10-2015

I love it Big Grin ahahah

Thanks for the support Smile


RE: Crazy with callbacks - CroNiX - 06-10-2015

did it work?


RE: Crazy with callbacks - StratoKyke - 06-10-2015

Yes Wink work it perfectly.


RE: Crazy with callbacks - Blair2004 - 06-10-2015

(06-10-2015, 05:37 AM)StratoKyke Wrote: 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) {
 
               $this->pages->title_check($title);
 }
 public function 
link_check_exist($link) {
 
               $this->pages->link_check($link);
 }
 
       public function create() {
 
               $rules = array(
 array(
 
'field'=>'title',
 
'label'=>'Titolo della pagina',
 
'rules'=>'alpha|required|min_length[3]|callback_title_check_exist'
 
),
 
                               array(
 
'field'=>'link',
 
'label'=>'Link della pagina',
 
'rules'=>'min_length[3]|required|callback_link_check_exist'
 
),
 
                               array(
 
'field'=>'message',
 
'label'=>'Testo della pagina',
 
'rules'=>'min_length[20]|required'
 
)

 );
.... 

Model:


PHP Code:
public function title_check($title) {
 
$db $this->load->database('default'TRUE);
 
$db->where('title',$title);
 
$query $db->get('pagine');
 if (
$query->num_rows() > 0){
 return 
TRUE;
 
$this->form_validation->set_message('title_check''Il titolo è già utilizzato.');
 }else{
 return 
FALSE;
 }
 }
 public function 
link_check($link) {
 
$db $this->load->database('default'TRUE);
 
$db->where('link',$link);
 
$query $db->get('pagine');
 if (
$query->num_rows() > 0){
 return 
TRUE;
 
$this->form_validation->set_message('link_check''Il link è già utilizzato.');
 }else{
 return 
FALSE;
 }
 } 

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. Big Grin

EDIT: I can try edit this part

PHP Code:
if ($query->num_rows() > 0){
 return 
TRUE;
 
$this->form_validation->set_message('title_check''Il titolo è già utilizzato.');
 }else{
 return 
FALSE;
 } 

with this code:

PHP Code:
if ($title 'title of page'){
 return 
TRUE;
 
$this->form_validation->set_message('title_check''Il titolo è già utilizzato.');
 }else{
 return 
FALSE;
 } 

and the result it is the same.
Why do you return before form validation set message use ???