Pass in request and resource into the form class

This increases the flexibility of what can be done in the form during
a POST or PUT request.
Fix missing JSON encoding of form errors