laminas / laminas-inputfilter

Normalize and validate input sets from the web, APIs, the CLI, and more, including files
https://docs.laminas.dev/laminas-inputfilter/
BSD 3-Clause "New" or "Revised" License
42 stars 28 forks source link

Add possibility to reference other input (using token name) from the same input filter #38

Open cbichis opened 3 years ago

cbichis commented 3 years ago

Feature Request

Q A
New Feature yes
RFC no
BC Break no

Summary

It would be nice to be able to get the filtered/validated value for other input element (referenced with token), as per form example for Identical Validator.

https://docs.laminas.dev/laminas-validator/validators/identical/#form-elements

Currently it seems impossible to do this. Even for Identical Validator this only can validate a static value, not other input value.

froschdesign commented 3 years ago

@cbichis You can use the callback validator and the second parameter on the callback function which provides all values of the input-filter:

https://github.com/laminas/laminas-inputfilter/blob/b6ab28b425e626b12488fec243e02d36d8dffeff/src/BaseInputFilter.php#L239-L241

https://github.com/laminas/laminas-inputfilter/blob/b6ab28b425e626b12488fec243e02d36d8dffeff/src/Input.php#L432-L433

cbichis commented 3 years ago

Thanks, @froschdesign . As far as I understand the value provided is the unfiltered/raw value not the filtered one (eventually even already validated better).

Let's give an example whys is this needed: let's say we have 2 inputs supplying id's. A second input having id may be correct depending on the first input with id.

Initially the first id is filtered (transforming the string id, trimming, striping tags and then looking up into database) into an object (or null if no object). Then another lookup may search by example into a m-m/1-m relation to see if the second id is valid...

froschdesign commented 3 years ago

@cbichis Any help is welcome, so pull requests are always appreciated. Go for it! 👍