Implemented submit functionality under 3 conditions