Factor out form handling code.

This should be a no-op. I need something along these lines for #4 and #5.