BUGFIX Validator/RequiredFields should not regard "0" as an empty value (from r108512)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112756 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-19 00:43:38 +00:00
parent b2c7c944de
commit c0e2017cfc
3 changed files with 4 additions and 4 deletions

View File

@ -123,7 +123,7 @@ class CustomRequiredFields extends RequiredFields{
eval($fieldName['php']); eval($fieldName['php']);
}else if($formField) { }else if($formField) {
// if an error is found, the form is returned. // if an error is found, the form is returned.
if(!$data[$fieldName] || preg_match('/^\s*$/', $data[$fieldName])) { if(!strlen($data[$fieldName]) || preg_match('/^\s*$/', $data[$fieldName])) {
$this->validationError( $this->validationError(
$fieldName, $fieldName,
sprintf(_t('Form.FIELDISREQUIRED', "%s is required."), sprintf(_t('Form.FIELDISREQUIRED', "%s is required."),

View File

@ -100,7 +100,7 @@ JS;
if($this->required) { if($this->required) {
foreach($this->required as $fieldName) { foreach($this->required as $fieldName) {
$formField = $fields->dataFieldByName($fieldName); $formField = $fields->dataFieldByName($fieldName);
if($formField && !$data[$fieldName]) { if($formField && !strlen($data[$fieldName])) {
$errorMessage = sprintf(_t('Form.FIELDISREQUIRED', '%s is required').'.', strip_tags('"' . ($formField->Title() ? $formField->Title() : $fieldName) . '"')); $errorMessage = sprintf(_t('Form.FIELDISREQUIRED', '%s is required').'.', strip_tags('"' . ($formField->Title() ? $formField->Title() : $fieldName) . '"'));
if($msg = $formField->getCustomValidationMessage()) { if($msg = $formField->getCustomValidationMessage()) {
$errorMessage = $msg; $errorMessage = $msg;

View File

@ -167,7 +167,7 @@ abstract class Validator extends Object {
} }
function requireField($fieldName, $data) { function requireField($fieldName, $data) {
if(!$data[$fieldName]) $this->validationError($fieldName, "$fieldName is required.", "required"); if(!strlen($data[$fieldName])) $this->validationError($fieldName, "$fieldName is required.", "required");
} }
function includeJavascriptValidation() { function includeJavascriptValidation() {