Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix required_without rule bug. #1742

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions system/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ public function required_without($str = null, string $fields, array $data): bool
// If the field is present we can safely assume that
// the field is here, no matter whether the corresponding
// search field is present or not.
$present = $this->required($data[$str] ?? null);
$present = $this->required($str ?? '');

if ($present === true)
if ($present)
{
return true;
}
Expand Down
24 changes: 17 additions & 7 deletions user_guide_src/source/libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -609,23 +609,33 @@ for rules like ``require_with`` that needs to check the value of another submitt
// If the field is present we can safely assume that
// the field is here, no matter whether the corresponding
// search field is present or not.
$present = $this->required($data[$str] ?? null);
$present = $this->required($str ?? '');

if ($present === true)
if ($present)
{
return true;
}

// Still here? Then we fail this test if
// Still here? Then we fail this test if
// any of the fields are present in $data
$requiredFields = array_intersect($fields, $data);
// as $fields is the lis
$requiredFields = [];

$requiredFields = array_filter($requiredFields, function($item)
foreach ($fields as $field)
{
return ! empty($item);
if (array_key_exists($field, $data))
{
$requiredFields[] = $field;
}
}

// Remove any keys with empty values since, that means they
// weren't truly there, as far as this is concerned.
$requiredFields = array_filter($requiredFields, function ($item) use ($data) {
return ! empty($data[$item]);
});

return ! (bool)count($requiredFields);
return empty($requiredFields);
}

Custom errors can be returned as the fourth parameter, just as described above.
Expand Down