add form validation and flash messages