Updated form validation function