ikkez / f3-validation-engine

Validation engine for Cortex and the PHP Fat-Free Framework
GNU General Public License v3.0
12 stars 2 forks source link

Get filtered values #11

Closed ponasromas closed 1 year ago

ponasromas commented 1 year ago

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 1 year ago

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

ponasromas commented 1 year ago

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