Move form logic into utils.py.