mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-25 19:09:52 +00:00
Making the form helper put the "required" class on all imputs that have a validation rule and does not explicitly sets allowEmpty => true in validation array
This commit is contained in:
parent
056b87d13a
commit
0ca5c11e6c
2 changed files with 5 additions and 8 deletions
|
@ -152,14 +152,11 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
|
||||
foreach ($validateProperties as $rule => $validateProp) {
|
||||
$rule = isset($validateProp['rule']) ? $validateProp['rule'] : false;
|
||||
if ($rule) {
|
||||
$rule = is_array($rule) ? array_shift($rule) : $rule;
|
||||
$rule = is_string($rule) ? strtolower($rule) : $rule;
|
||||
if (isset($validateProp['allowEmpty']) && $validateProp['allowEmpty'] === true) {
|
||||
return false;
|
||||
}
|
||||
$required = empty($validateProp);
|
||||
$required = $required || (!empty($rule) && $rule === 'notempty');
|
||||
$required = $required || (isset($validateProp['allowEmpty']) && $validateProp['allowEmpty'] !== true);
|
||||
$rule = isset($validateProp['rule']) ? $validateProp['rule'] : false;
|
||||
$required = $rule || empty($validateProp);
|
||||
if ($required) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ class Contact extends CakeTestModel {
|
|||
'imalsorequired' => array('rule' => 'alphaNumeric', 'allowEmpty' => false),
|
||||
'imrequiredtoo' => array('rule' => 'notEmpty'),
|
||||
'required_one' => array('required' => array('rule' => array('notEmpty'))),
|
||||
'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric'),
|
||||
'imnotrequired' => array('required' => false, 'rule' => 'alphaNumeric', 'allowEmpty' => true),
|
||||
'imalsonotrequired' => array('alpha' => array('rule' => 'alphaNumeric','allowEmpty' => true),
|
||||
'between' => array('rule' => array('between', 5, 30))));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue