Added form validation related code
Changed variable names, fixed a typo.