BUGFIX (by cinek) PHP validation field name for [Custom]RequiredField: Server side validation displays field name instead of field label in messages, e.g. "EditableEmailField?1 is required" instead of e.g. "E-mail address is required" for a field with label "Email address". (patch from #2560)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@58305 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-07-17 21:58:59 +00:00
parent fac78448a7
commit 1a4212602f
2 changed files with 16 additions and 14 deletions

View File

@ -32,7 +32,7 @@ class CustomRequiredFields extends RequiredFields{
if(is_array($this->required)){ if(is_array($this->required)){
foreach($this->required as $field) { foreach($this->required as $field) {
if(is_array($field) && $field['js']){ if(is_array($field) && isset($field['js'])){
$code .= $field['js'] . "\n"; $code .= $field['js'] . "\n";
}else if($fields->dataFieldByName($field)) { }else if($fields->dataFieldByName($field)) {
$code .= " require('$field');\n"; $code .= " require('$field');\n";
@ -56,15 +56,17 @@ class CustomRequiredFields extends RequiredFields{
$valid = ($field->validate($this) && $valid); $valid = ($field->validate($this) && $valid);
} }
if($this->required){ if($this->required){
foreach($this->required as $key => $field) { foreach($this->required as $key => $fieldName) {
if(is_array($field) && $field['php']){ $formField = $fields->dataFieldByName($fieldName);
eval($field['php']); if(is_array($fieldName) && isset($fieldName['php'])){
}else if($fields->dataFieldByName($field)) { eval($fieldName['php']);
}else if($formField) {
// if an error is found, the form is returned. // if an error is found, the form is returned.
if(!$data[$field] || preg_match('/^\s*$/', $data[$field])) { if(!$data[$fieldName] || preg_match('/^\s*$/', $data[$fieldName])) {
$this->validationError( $this->validationError(
$field, $fieldName,
sprintf(_t('Form.FIELDISREQUIRED', "%s is required"), $field), sprintf(_t('Form.FIELDISREQUIRED', "%s is required"),
$formField->Title()),
"required" "required"
); );
return false; return false;

View File

@ -95,14 +95,14 @@ JS;
$valid = ($field->validate($this) && $valid); $valid = ($field->validate($this) && $valid);
} }
if($this->required) { if($this->required) {
foreach($this->required as $field) { foreach($this->required as $fieldName) {
$fieldObj = $fields->dataFieldByName($field); $formField = $fields->dataFieldByName($fieldName);
if($fieldObj && !$data[$field]) { if($formField && !$data[$fieldName]) {
$this->validationError( $this->validationError(
$field, $fieldName,
sprintf( sprintf(
_t('Form.FIELDISREQUIRED'), _t('Form.FIELDISREQUIRED'),
strip_tags($fieldObj->Title()) strip_tags($formField->Title())
), ),
"required" "required"
); );