Why do you do a database query before the form validation? If the form is invalid, you have queries postgres for nothing.