ikkez/f3-validation-engine

Get filtered values

Closed this issue · 2 comments

How to get filtered values?

$data = [
  'username' => 'Jonny',
  'email' => 'john.doe@domain.com',
];
$rules = [
  'username' => [
    'filter' => 'trim',
    'validate' => 'required|min_len,10|max_len,128|unique',
  ],
  'email' => [
    'filter' => 'trim',
    'validate' => 'required|valid_email|email_host',
  ]
];
$valid = $validation->validate($rules, $data);

Returns only TRUE/FALSE. In GUMP there was approach like this:

$valid = $validation->validate($rules, $data);

if validation was "TRUE", than $valid['username'] return filtered value. How to achieve this?

ikkez commented

the filter is automatically applied to $data. As $data is handled as reference, the filter is already applied to $data after calling this function.

Aha, got it. A bit magical :) but convenient.