Fixed error calculation when submitting form