mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
fac78448a7
commit
1a4212602f
@ -32,7 +32,7 @@ class CustomRequiredFields extends RequiredFields{
|
||||
if(is_array($this->required)){
|
||||
|
||||
foreach($this->required as $field) {
|
||||
if(is_array($field) && $field['js']){
|
||||
if(is_array($field) && isset($field['js'])){
|
||||
$code .= $field['js'] . "\n";
|
||||
}else if($fields->dataFieldByName($field)) {
|
||||
$code .= " require('$field');\n";
|
||||
@ -56,15 +56,17 @@ class CustomRequiredFields extends RequiredFields{
|
||||
$valid = ($field->validate($this) && $valid);
|
||||
}
|
||||
if($this->required){
|
||||
foreach($this->required as $key => $field) {
|
||||
if(is_array($field) && $field['php']){
|
||||
eval($field['php']);
|
||||
}else if($fields->dataFieldByName($field)) {
|
||||
foreach($this->required as $key => $fieldName) {
|
||||
$formField = $fields->dataFieldByName($fieldName);
|
||||
if(is_array($fieldName) && isset($fieldName['php'])){
|
||||
eval($fieldName['php']);
|
||||
}else if($formField) {
|
||||
// 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(
|
||||
$field,
|
||||
sprintf(_t('Form.FIELDISREQUIRED', "%s is required"), $field),
|
||||
$fieldName,
|
||||
sprintf(_t('Form.FIELDISREQUIRED', "%s is required"),
|
||||
$formField->Title()),
|
||||
"required"
|
||||
);
|
||||
return false;
|
||||
@ -83,4 +85,4 @@ class CustomRequiredFields extends RequiredFields{
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
@ -95,14 +95,14 @@ JS;
|
||||
$valid = ($field->validate($this) && $valid);
|
||||
}
|
||||
if($this->required) {
|
||||
foreach($this->required as $field) {
|
||||
$fieldObj = $fields->dataFieldByName($field);
|
||||
if($fieldObj && !$data[$field]) {
|
||||
foreach($this->required as $fieldName) {
|
||||
$formField = $fields->dataFieldByName($fieldName);
|
||||
if($formField && !$data[$fieldName]) {
|
||||
$this->validationError(
|
||||
$field,
|
||||
$fieldName,
|
||||
sprintf(
|
||||
_t('Form.FIELDISREQUIRED'),
|
||||
strip_tags($fieldObj->Title())
|
||||
strip_tags($formField->Title())
|
||||
),
|
||||
"required"
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user