Open mikejw opened 6 years ago
I have experienced the exact same issue. I tried to write a 'present' rule where the field just needs to be preset in the input regardless of emptiness. Come to find out that the input index needs to be there for the rule to be ran however for some reason this works with the 'required' rule. You would think the functionality would be there to do so.
From the readme: "Using an extra parameter, you can make this rule more flexible, and only check if the field exists in the data array."
$v->rule('required', 'field_name', true);
Having the extra parameter set to "true", the rule will only check if the key is present in the data array :)
@willemwollebrants Thank you. Yes, I saw this but the main issue is unsolved. Can you please reopen the issue. The main issue is that custom rules are not applied unless the input filed is there.
I think that using the required rule with the extra parameter does what you want for a "present" rule: it checks if the field is set in the input and it can be empty.
Can you show me a piece of code that has the problem?
Experience the same issue.
I got the same issue. In my case, I want to make a custom rule requiredIf
, means this field is required when match a condition. Nothing happens if I don't use with 'required'.
how can i solve this. fields:
foo, bar, baz, xyz
foo and bar are boolean, bar and xyz numeric or null.
i need to check, if foo is true then bar cannot be null or less than 0
I have two custom validation rules:
` Validator::addRule('requiredIfUK', function($field, $value, array $params, array $fields) {
` countryIsSet is applied but requiredIfUK is not. Perhaps because postcode is not in the required list?