current selection and refine the original author's code to this function, also added form data handler