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

Validation - permit_empty #830

Closed
natanfelles opened this issue Nov 10, 2017 · 5 comments
Closed

Validation - permit_empty #830

natanfelles opened this issue Nov 10, 2017 · 5 comments

Comments

@natanfelles
Copy link
Contributor

On CI 3, input data sent with blank values are accepted by Form Validation.

For example:

If exists rules to a email field like it: valid_email|is_unique[users.email], the validation accepts blank values, a string ''. Of course '' is not a valid_email. I believe that the validation must fail. But I see that this also occurs in others frameworks, accepting '' as a valid email, if is not set the required rule for example.

On CI 4 it is not happening. If the user send '' and exist a valid_email then the validation show the error. Because '' is not a valid email. I think this a best way to validate.

If the user do not send the field email (think about an API) and it have not the required rule, then the validation pass. But if he send a blank value the Validation show the error... OK.

But a third use case, and common. And, what about if is possible to receive an empty value? Having the valid_email rule the Validation do not accept ''.

An possible solution, I think, could be an rule to permit this use case. Like a permit_empty, that would cancel all other field rules if the value is empty.

If what I tried to explain could be confuse, please see:

@lonnieezell
Copy link
Member

Laravel has something similar, the sometimes rule. In this described case, though, and blank string equates to "empty", and is likely what the user would get back from the form. I don't have problems with this idea, but if we're going to allow empty should probably allow all version of empty, including a blank string.

@natanfelles
Copy link
Contributor Author

The first thing to think can be: Then the required rule is not necessary? Yes. It is. But means required could hold the field and not the value.

If is required, then the field MUST be sent. And can be an empty string if is accepted. But the field MUST be sent.

@natanfelles
Copy link
Contributor Author

Yes. I believe that an null value could be sent/accepted. But the field of this empty value must be received (if required).

@natanfelles
Copy link
Contributor Author

I did not know the sometimes rule. But, yes, according to this question is the same thing that I think about.

@natanfelles
Copy link
Contributor Author

Related to #614

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

No branches or pull requests

2 participants