designing algorithm for form field data insertion