Refactor duplicated form code in new and edit views