move form validation code to global