Why is my form hangs on clicking submit?