Welcome Guest, Not a member yet? Register   Sign In
validation problem
#1

[eluser]dimis[/eluser]
I want to see if a text input is empty when a condition exists.
So I extend validation and write this function.
Code:
function _check_text($str,$type)
    {
        
       if (empty($str) && $type['item']==$type['value'] )
        {
            $this->set_message('_check_text',"You must fill .");
            return FALSE;

       }
       return TRUE;
    }
But it does not work.How can I find if the value of the input is empty?
Dimis
#2

[eluser]xwero[/eluser]
The required rule is to check if the field as a value. If the required rule isn't added and there is no value all the rules are omitted.
#3

[eluser]dimis[/eluser]
I want only if $type['item']==$type['value'] to fill this input.
is it Impossible?
#4

[eluser]xwero[/eluser]
I don't think your check will ever be true or will always be true. The way your $type[‘item’]==$type[‘value’] works if you add an array to as the parameter to the rule with the keys item and value. The type of a POST value is most of the time a string but because php has weak typing you can check if it's numeric too. The numeric rule is in the Validation library and it also as a few rules to check the formating of the string.

You could add a check to see if the value for the post key is an array but that is it so your function would look like this
Code:
function($val,$type)
{
    $types = array('string','numeric','float','array');

    if( ! in_array($type,$types))
    {
       return FALSE;
    }

    $function = 'is_'.$type;

    if( ! $function($val))
    {
       return FALSE;
    }

    return TRUE;
}
#5

[eluser]dimis[/eluser]
My code is
Code:
$test=array('item'=>$mylink,'value'=>'1');
$rules['path']    = "_check_text[$test]";
But if I can not use the empty function is useless
#6

[eluser]xwero[/eluser]
You have to add the required rule. If there is no value there is no point of getting the type.
#7

[eluser]dimis[/eluser]
Anyway, I put the conditions at my controller
(if $check==something)
...
validation rules
....




Theme © iAndrew 2016 - Forum software by © MyBB