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

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

Open
cbichis opened this issue Oct 25, 2021 · 3 comments

Comments

@cbichis
Copy link

cbichis commented Oct 25, 2021

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
Copy link
Member

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

protected function validateInputs(array $inputs, $data = [], $context = null)
{
$inputContext = $context ?: (array_merge($this->getRawValues(), (array) $data));

$validator = $this->getValidatorChain();
$result = $validator->isValid($value, $context);

@cbichis
Copy link
Author

cbichis commented Oct 26, 2021

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants