CodeIgniter Forums
validation problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: validation problem (/thread-12097.html)



validation problem - El Forum - 10-06-2008

[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


validation problem - El Forum - 10-06-2008

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


validation problem - El Forum - 10-06-2008

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


validation problem - El Forum - 10-06-2008

[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;
}



validation problem - El Forum - 10-06-2008

[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


validation problem - El Forum - 10-06-2008

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


validation problem - El Forum - 10-06-2008

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