Factor form logic out of the popup module