Skip to content

Commit c32c295

Browse files
committed
feat: return only validated content
1 parent d7a43c8 commit c32c295

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/Form.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Form
7676
'max' => '{Field} must not exceed %s characters',
7777
'between' => '{Field} must be between %s and %s characters long',
7878
'match' => '{Field} must match the %s field',
79+
'matchesvalueof' => '{Field} must match the value of %s',
7980
'contains' => '{Field} must contain %s',
8081
'boolean' => '{Field} must be a boolean',
8182
'truefalse' => '{Field} must be a boolean',
@@ -132,7 +133,6 @@ public function __construct()
132133
};
133134

134135
$this->rules['matchesvalueof'] = function ($value, $param) {
135-
$this->message('matchesvalueof', "{field} must match the value of $param");
136136
return \Leaf\Http\Request::get($param) === $value;
137137
};
138138
}
@@ -271,17 +271,23 @@ public function validate(array $dataSource, array $validationSet)
271271
// clear previous errors
272272
$this->errors = [];
273273

274-
$output = $dataSource;
274+
$output = [];
275275

276276
foreach ($validationSet as $itemToValidate => $userRules) {
277277
if (empty($userRules)) {
278+
$output[$itemToValidate] = Anchor::deepGetDot($dataSource, $itemToValidate);
278279
continue;
279280
}
280281

282+
$endsWithWildcard = substr($itemToValidate, -1) === '*';
283+
$itemToValidate = $endsWithWildcard ? substr($itemToValidate, 0, -1) : $itemToValidate;
284+
281285
$value = Anchor::deepGetDot($dataSource, $itemToValidate);
282286

283287
if (!$this->test($userRules, $value, $itemToValidate)) {
284288
$output = false;
289+
} else if ($output !== false && !$endsWithWildcard) {
290+
$output = Anchor::deepSetDot($output, $itemToValidate, $value);
285291
}
286292
}
287293

0 commit comments

Comments
 (0)