PHP validation for a field only in create windows from and not in edit windows form

PHP validation for a field only in create windows from and not in edit windows form

lxs977lxs977 Posts: 1Questions: 1Answers: 0

I validate a field in the creation windows form for required field and so unique:

    Field::inst( 'barcode' )
        ->validator( function($val, $data, $opts) {
            global $db;
                if ( empty($val) ) {
                   return "Codice a Barre obbligatorio";
                }else{
                $checkdup = $db
                ->select( 'listino', 'id', array(
                    'barcode' => mysql_real_escape_string($val)
                ))
                ->count();
                    if($checkdup !== 0){
                    return "Codice a Barre esistente";
                }
            }
                return true; 
        } ),

the problem that in edit windows form I should not validate the field, is possible?

sorry for my english, I hope I explained

This discussion has been closed.