- Timestamp:
- 03/17/10 23:59:37 (4 months ago)
- Files:
-
- fORMValidation.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
fORMValidation.php
r742 r787 Hide Line Numbers 3 3 * Handles validation for fActiveRecord classes 4 4 * 5 * @copyright Copyright (c) 2007-20 09Will Bond, others5 * @copyright Copyright (c) 2007-2010 Will Bond, others 6 6 * @author Will Bond [wb] <will@flourishlib.com> 7 7 * @author Jeff Turcotte [jt] <jeff.turcotte@gmail.com> … … 11 11 * @link http://flourishlib.com/fORMValidation 12 12 * 13 * @version 1.0.0b22 13 * @version 1.0.0b23 14 * @changes 1.0.0b23 Added support for checking integers and floats to ensure they fit within the range imposed by the database schema [wb, 2010-03-17] 14 15 * @changes 1.0.0b22 Made the value checking for one-or-more and only-one rules more robust when detecting the absence of a value [wb, 2009-12-17] 15 16 * @changes 1.0.0b21 Fixed a bug affecting where conditions with columns that are not null but have a default value [wb, 2009-11-03] … … 374 375 $table = fORM::tablize($class); 375 376 376 $schema = fORMSchema::retrieve($class);377 $ column_info= $schema->getColumnInfo($table, $column);377 $schema = fORMSchema::retrieve($class); 378 $info = $schema->getColumnInfo($table, $column); 378 379 // Make sure a value is provided for required columns 379 if ($values[$column] === NULL && $ column_info['not_null'] && $column_info['default'] === NULL && $column_info['auto_increment'] === FALSE) {380 if ($values[$column] === NULL && $info['not_null'] && $info['default'] === NULL && $info['auto_increment'] === FALSE) { 380 381 return self::compose( 381 382 '%sPlease enter a value', … … 388 389 389 390 // Make sure a valid value is chosen 390 if (isset($ column_info['valid_values']) && $values[$column] !== NULL && !in_array($values[$column], $column_info['valid_values'])) {391 if (isset($info['valid_values']) && $values[$column] !== NULL && !in_array($values[$column], $info['valid_values'])) { 391 392 return self::compose( 392 393 '%1$sPlease choose from one of the following: %2$s', 393 394 fValidationException::formatField(fORM::getColumnName($class, $column)), 394 join(', ', $ column_info['valid_values'])395 join(', ', $info['valid_values']) 395 396 ); 396 397 } 397 398 398 399 // Make sure the value isn't too long 399 if ($ column_info['type'] == 'varchar' && isset($column_info['max_length']) && $values[$column] !== NULL && is_string($values[$column]) && fUTF8::len($values[$column]) > $column_info['max_length']) {400 if ($info['type'] == 'varchar' && isset($info['max_length']) && $values[$column] !== NULL && is_string($values[$column]) && fUTF8::len($values[$column]) > $info['max_length']) { 400 401 return self::compose( 401 402 '%1$sPlease enter a value no longer than %2$s characters', 402 403 fValidationException::formatField(fORM::getColumnName($class, $column)), 403 $ column_info['max_length']404 $info['max_length'] 404 405 ); 405 406 } 406 407 407 408 // Make sure the value is the proper length 408 if ($ column_info['type'] == 'char' && isset($column_info['max_length']) && $values[$column] !== NULL && is_string($values[$column]) && fUTF8::len($values[$column]) != $column_info['max_length']) {409 if ($info['type'] == 'char' && isset($info['max_length']) && $values[$column] !== NULL && is_string($values[$column]) && fUTF8::len($values[$column]) != $info['max_length']) { 409 410 return self::compose( 410 411 '%1$sPlease enter exactly %2$s characters', 411 412 fValidationException::formatField(fORM::getColumnName($class, $column)), 412 $column_info['max_length'] 413 $info['max_length'] 414 ); 415 } 416 417 // Make sure the value fits in the numeric range 418 if (self::stringlike($values[$column]) && in_array($info['type'], array('integer', 'float')) && $info['min_value'] && $info['max_value'] && ($info['min_value']->gt($values[$column]) || $info['max_value']->lt($values[$column]))) { 419 return self::compose( 420 '%1$sPlease enter a number between %2$s and %3$s', 421 fValidationException::formatField(fORM::getColumnName($class, $column)), 422 $info['min_value']->__toString(), 423 $info['max_value']->__toString() 413 424 ); 414 425 } … … 1419 1430 1420 1431 /** 1421 * Copyright (c) 2007-20 09Will Bond <will@flourishlib.com>, others1432 * Copyright (c) 2007-2010 Will Bond <will@flourishlib.com>, others 1422 1433 * 1423 1434 * Permission is hereby granted, free of charge, to any person obtaining a copy
