How do I properly handle a Uniqueness validation in a form?

Hi,

I see there is a model validator, Phalcon\Mvc\Models\Validator\Uniqueness, that accomplishes my needs to make sure that a username is not taken on a registration form. However, my form is using the Phalcon\Validation\Validator classes to validate the registration form.

  • How can I do a Uniqueness validation here?
  • Do I have to implement a custom validator?

Thanks



37.7k

Hey

When submit from it checking data in your database , so i think you should use Phalcon\Mvc\Models\Validator\Uniqueness in model, also refer sample app https://github.com/phalcon/vokuro

edited Sep '14

I have installed the sample app and will take a look.

I am aware of the ability to check the uniqueness on the model, but I feel as if I should be checking it in the form validation. The error messages are grouped based on field in the form validation, so having that one validation in only the model would complicate things, would it not?

Do you understand why I feel like the validation for the uniqueness should be part of the rest of the form validation?

Maybe I am thinking of it wrong.

Edit: I have tried out the registration form in vokuro. It does not display error messages when I attempt to register with an already taken email. (Actually, it's crashing when I submit duplicate information... I'll look into why)



99

Hi, good discuss