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

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

I love it Big Grin ahahah

Thanks for the support Smile
Reply
#13

did it work?
Reply
#14

Yes Wink work it perfectly.
Reply
#15

(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 ???
NexoPOS 2.6.2 available on CodeCanyon.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB