refactored form validation on front-end