Welcome Guest, Not a member yet? Register   Sign In
Validation Callbacks!!!
#1

[eluser]reset[/eluser]
Hello all!!

I have a form with two multiple list. I move options from one multiple to the other one in order that the user want. I must validate that first multiple is empty and the other one have all the options...

How I can do that? I do this, but doesn't work, sorry for my english:

Code:
$rules['grupos1'] = 'empty';
$rules['grupos2'] = 'required';
//or
$rules['grupos1'] = 'callback_empty';
$rules['grupos2'] = 'required';
//don't work

$grupos_1 = $this->input->post('grupos1');
if (empty($grupos_1)) echo 'TRUE';
//print TRUE

Thanks
#2

[eluser]Bramme[/eluser]
I don't really understand what you need. Could you show us the page (or maybe even just a screenshot) and try to explain a bit better what you need.
#3

[eluser]reset[/eluser]
Hello Bramme, I attach one file with two screenshot.

- The first is the initial state for the user.
- In the second, the user selects all options in the first "multiple select" and put into the second in the order that he wants.

I must validate that first multiple select is empty, and I have tried the options that I related in the first post.

Thanks
#4

[eluser]reset[/eluser]
I do that in MY_Validation, and works, but I don't know if it is necessary.

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Validation extends CI_Validation{

    function MY_Validation(){
        parent::CI_Validation();
        log_message('debug', 'MY_Validatin Class Initialized');
    }
    
...
    
    function is_empty($param){
        return empty($param);
    }
    

}
?>;

And I do this for validation:
Code:
$rules['grupos1'] = 'is_empty';
#5

[eluser]reset[/eluser]
have somebody any idea?
#6

[eluser]Bramme[/eluser]
I don't see a reason why you would extend the CI_Validation library. And you started off good, you have to make your own custom callbacks...

Code:
$rules['grupos1'] = 'callback_empty';
$rules['grupos2'] = 'required';
//or
$rules['grupos1'] = 'callback_empty';
$rules['grupos2'] = 'required';
//don't work

$grupos_1 = $this->input->post('grupos1');
if (empty($grupos_1)) echo 'TRUE';
//print TRUE

You don't have to echo true though. Add this to your controller:

Code:
function empty($str) {
    
    if(empty($str)) {
        return true;
    } else {
        $this->validation->set_message('empty', 'First group is not empty');
        return false;
    }
}
#7

[eluser]reset[/eluser]
Hi Bramme, I add empty to MY_Validation, and it doesn't work.

My Code is:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Validation extends CI_Validation{

    function MY_Validation(){
        parent::CI_Validation();
        log_message('debug', 'MY_Validatin Class Initialized');
    }
    
    function greaterthan_sysdate($date){
        $sysdate = date('Ymd');
        $date = substr($date,6).substr($date,3,2).substr($date,0,2);
        if ($date > $sysdate)
            return TRUE;
        return FALSE;    
    }

    function check_date_format($date){
        $ddmmyyyy='(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)[0-9]{2}';
           if(preg_match("/$ddmmyyyy$/", $date))
            return TRUE;
        return FALSE;
    }

    function check_date($date){
        if (checkdate((int) substr($date,3,2),(int) substr($date,0,2), (int) substr($date,6)))
                return TRUE;
        return FALSE;
    }
    
    function empty($param){ //line 31
        return empty($param);
    }
    
    function is_array($param){
        return is_array($param);
    }
    

}
?>

And that is the error:
Parse error: parse error, unexpected T_EMPTY, expecting T_STRING in C:\Program Files\EasyPHP 2.0b1\www\uahlabs\system\application\libraries\MY_Validation.php on line 31

Thanks
#8

[eluser]Bramme[/eluser]
try changing it to
Code:
if(empty($param)) {
return true;
}else {
return false;
}
maybe?
#9

[eluser]reset[/eluser]
Hi Bramme,

It doesn't work because 'empty' is one of words of the "List of Reserved Words" of php. I thought that could calling php functions from "validation rules" but I see that this is not possible.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB