Created
May 31, 2012 14:23
-
-
Save anonymous/2843713 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Validation extends Fuel\Core\Validation{ | |
public static function _validation_unique($val, $options) | |
{ | |
list($table, $field) = explode('.', $options); | |
$result = DB::select(strtolower($field)) | |
->where($field, '=', Str::lower($val)) | |
->from($table)->execute('default'); | |
Validation::active()->set_message('unique', ':label must be unique.'); | |
return ! ($result->count() > 0); | |
} | |
public static function _validation_billing_address($val) | |
{ | |
if(empty($val['inactive'])) | |
{ | |
if(empty($val['add1'])) | |
{ | |
Validation::active()->set_message('billing_address', 'The field Address is required for :label'); | |
return false; | |
} | |
if(empty($val['city'])) | |
{ | |
Validation::active()->set_message('billing_address', 'The field City is required for :label'); | |
return false; | |
} | |
if(empty($val['code'])) | |
{ | |
Validation::active()->set_message('billing_address', 'The field Postcode is required for :label'); | |
return false; | |
} | |
if(empty($val['country'])) | |
{ | |
Validation::active()->set_message('billing_address', 'The field Country is required for :label'); | |
return false; | |
} | |
} | |
return true; | |
} | |
public static function _validation_currency($val) | |
{ | |
if(!empty($val)) | |
{ | |
if(!is_numeric($val) && !preg_match('/\b\d{1,3}(?:,?\d{3})*(?:\.\d{2})?\b/', $val)) | |
{ | |
Validation::active()->set_message('currency', 'The field :label currency format is invalid'); | |
return false; | |
} | |
} | |
return true; | |
} | |
public static function _validation_location($val) | |
{ | |
if(empty($val['add1'])) | |
{ | |
Validation::active()->set_message('location', 'The Address field is required for :label'); | |
return false; | |
} | |
if(empty($val['city'])) | |
{ | |
Validation::active()->set_message('location', 'The Town / City field is required for :label'); | |
return false; | |
} | |
if(empty($val['code'])) | |
{ | |
Validation::active()->set_message('location', 'The Postal / Zip code field is required for :label'); | |
return false; | |
} | |
if(empty($val['country'])) | |
{ | |
Validation::active()->set_message('location', 'The Country field is required for :label'); | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment