Welcome Guest, Not a member yet? Register   Sign In
Validation Placeholders being ignored for is_unique
#2

Something like this?

PHP Code:
    public function is_unique(string $str nullstring $field, array $data): bool
    
{
        
// Grab any data for exclusion of a single row.
        
list($field$ignoreField$ignoreValue) = array_pad(explode(','$field), 3null);

        
// Break the table and field apart
        
sscanf($field'%[^.].%[^.]'$table$field);

        
$db Database::connect();
        
        
$row $db->table($table)
                 
 ->select('1')
                 
 ->where($field$str)
                 
 ->limit(1);

        if ( ! empty(
$ignoreField) && ! empty($ignoreValue))
        {
            if (
$ignoreValue[0] == '{') {
                
$key substr($ignoreValue1, -1);
                
                if (isset(
$data[$key]))
                    
$ignoreValue $data[$key];
            }
            
            
$row $row->where("{$ignoreField} !="$ignoreValue);
        }

        return (bool) (
$row->get()
                        ->
getRow() === null);
    } 
Reply


Messages In This Thread
RE: Validation Placeholders being ignored for is_unique - by NiteRaven - 11-26-2018, 11:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB