move validation code to form factory