You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears this validation middleware does not allow you to reference other $_POST values and create dynamic validation based on their values. Is there a way to do this?
For example, if a user selects NY as their state then I need them to input their email and license. Currently I'm doing it like this...
I would like to pass in the Respect object without having to manually check the $_POST['state'] value. Can I format the $validator in a way that can reference other keys?
Here is the Respect way of doing it.
$_POST = [
'state' => 'NY',
'email' => '[email protected]',
'license' => 'MIT'
];
$result = v::key('state', v::subdivisionCode('US')->notOptional())
->when(
v::key('state', v::equals('NY')), // if state = NY
v::key('email', v::notOptional()->email()), // then add validation to email
v::alwaysValid() // else email is always valid
)
->when(
v::key('state', v::equals('NY')), // if state = NY
v::key('license', v::notOptional()), // then make license required
v::alwaysValid() // else license is always valid
)
->validate($_POST);
The text was updated successfully, but these errors were encountered:
Hi @eko3alpha . Sorry for the late response. You can try the version that is under development here: #40. It does support your use case and you can also see some green tests based on your issue: 15de8fd
Please, let me know if it works for you.
It appears this validation middleware does not allow you to reference other $_POST values and create dynamic validation based on their values. Is there a way to do this?
For example, if a user selects NY as their state then I need them to input their email and license. Currently I'm doing it like this...
I tried doing this but it's not working.
I would like to pass in the Respect object without having to manually check the $_POST['state'] value. Can I format the $validator in a way that can reference other keys?
Here is the Respect way of doing it.
The text was updated successfully, but these errors were encountered: