Added validation to the JavaScript form submission