Add form fields.

This pull request also adds tests for model fields and cleans up some code.