I have two fields and one of them is required if the value of the other is equal to one condition.
How can I do this?
The "campaignFranchise" field is only required when the value of the "campaign" is equal to "franchise".
4 => [
'required' => true,
'validators' => [
0 => [
'name' => NotEmpty::class,
'options' => [...],
],
1 => [
'name' => StringLength::class,
'options' => [...],
],
],
'filters' => [...],
'name' => 'campaign',
],
5 => [
'required' => true,
'validators' => [
0 => [
'name' => NotEmpty::class,
'options' => [
'translatorenabled' => true,
],
'break_chain_on_failure' => true,
],
1 => [
'name' => Callback::class,
'options' => [
'callback' => [
CampaignFranchise::class,
'isValid',
],
],
],
2 => [
'name' => StringLength::class,
'options' => [...],
],
],
'filters' => [...],
'name' => 'campaignFranchise',
],
I try use "continueIfEmpty" and "allowEmpty" but how I don't have value and is required, the validation return false.
https://github.com/zendframework/zend-inputfilter/blob/master/src/Input.php#L410-415
If the field is required false, the validation does not trigger.
https://github.com/zendframework/zend-inputfilter/blob/master/src/BaseInputFilter.php#L251-L256
And if I use the callback validator in "campaign" field, the message error result display in wrong field.
I have two fields and one of them is required if the value of the other is equal to one condition.
How can I do this?
The "campaignFranchise" field is only required when the value of the "campaign" is equal to "franchise".
4 => [ 'required' => true, 'validators' => [ 0 => [ 'name' => NotEmpty::class, 'options' => [...], ], 1 => [ 'name' => StringLength::class, 'options' => [...], ], ], 'filters' => [...], 'name' => 'campaign', ], 5 => [ 'required' => true, 'validators' => [ 0 => [ 'name' => NotEmpty::class, 'options' => [ 'translatorenabled' => true, ], 'break_chain_on_failure' => true, ], 1 => [ 'name' => Callback::class, 'options' => [ 'callback' => [ CampaignFranchise::class, 'isValid', ], ], ], 2 => [ 'name' => StringLength::class, 'options' => [...], ], ], 'filters' => [...], 'name' => 'campaignFranchise', ],I try use "continueIfEmpty" and "allowEmpty" but how I don't have value and is required, the validation return false.
https://github.com/zendframework/zend-inputfilter/blob/master/src/Input.php#L410-415
If the field is required false, the validation does not trigger.
https://github.com/zendframework/zend-inputfilter/blob/master/src/BaseInputFilter.php#L251-L256
And if I use the callback validator in "campaign" field, the message error result display in wrong field.