Welcome Guest, Not a member yet? Register   Sign In
Crazy with callbacks
#1

(This post was last modified: 06-10-2015, 05:48 AM by StratoKyke.)

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.
Reply


Messages In This Thread
Crazy with callbacks - by StratoKyke - 06-10-2015, 05:37 AM
RE: Crazy with callbacks - by StratoKyke - 06-10-2015, 05:59 AM
RE: Crazy with callbacks - by CroNiX - 06-10-2015, 06:34 AM
RE: Crazy with callbacks - by StratoKyke - 06-10-2015, 06:37 AM
RE: Crazy with callbacks - by CroNiX - 06-10-2015, 06:41 AM
RE: Crazy with callbacks - by StratoKyke - 06-10-2015, 06:45 AM
RE: Crazy with callbacks - by CroNiX - 06-10-2015, 06:49 AM
RE: Crazy with callbacks - by StratoKyke - 06-10-2015, 06:52 AM
RE: Crazy with callbacks - by CroNiX - 06-10-2015, 07:01 AM
RE: Crazy with callbacks - by StratoKyke - 06-10-2015, 07:07 AM
RE: Crazy with callbacks - by CroNiX - 06-10-2015, 07:12 AM
RE: Crazy with callbacks - by StratoKyke - 06-10-2015, 07:23 AM
RE: Crazy with callbacks - by CroNiX - 06-10-2015, 07:38 AM
RE: Crazy with callbacks - by StratoKyke - 06-10-2015, 08:38 AM
RE: Crazy with callbacks - by Blair2004 - 06-10-2015, 11:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB