Skip to content

Commit

Permalink
Returning null for get(Required|NotEmpty)Message when no ValidationSe…
Browse files Browse the repository at this point in the history
…t exists for the field
  • Loading branch information
jeremyharris committed Apr 4, 2018
1 parent e3af681 commit f6b6bdc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Validation/Validator.php
Expand Up @@ -1933,10 +1933,14 @@ public function regex($field, $regex, $message = null, $when = null)
* Gets the required message for a field
*
* @param string $field Field name
* @return string
* @return string|null
*/
public function getRequiredMessage($field)
{
if (!isset($this->_fields[$field])) {
return null;
}

$defaultMessage = 'This field is required';
if ($this->_useI18n) {
$defaultMessage = __d('cake', 'This field is required');
Expand All @@ -1951,21 +1955,23 @@ public function getRequiredMessage($field)
* Gets the notEmpty message for a field
*
* @param string $field Field name
* @return string
* @return string|null
*/
public function getNotEmptyMessage($field)
{
if (!isset($this->_fields[$field])) {
return null;
}

$defaultMessage = 'This field cannot be left empty';
if ($this->_useI18n) {
$defaultMessage = __d('cake', 'This field cannot be left empty');
}

$notBlankMessage = null;
if (isset($this->_fields[$field])) {
foreach ($this->_fields[$field] as $rule) {
if ($rule->get('rule') === 'notBlank' && $rule->get('message')) {
return $rule->get('message');
}
foreach ($this->_fields[$field] as $rule) {
if ($rule->get('rule') === 'notBlank' && $rule->get('message')) {
return $rule->get('message');
}
}

Expand Down

0 comments on commit f6b6bdc

Please sign in to comment.