Updated form function and added error messages for save failures