On Mon, Oct 8, 2012 at 12:55 PM, Randall Leeds <[email protected]> wrote: > On Sun, Oct 7, 2012 at 6:24 AM, Mark Huang <[email protected]> wrote: >> Ok I have another question.... >> >> Do all the form packages like formalchemy or Deform assume that forms are >> submitted via a "form submit" action? >> >> I am contemplating on using Deform for my form validations, but I am >> currently submitting the forms using an AJAX POST request; sending data as >> JSON to the backend Pyramid. Why? Well, the forms are a bit complex and >> because I use CouchDB, the JSON is easily saved. The problem is, I need to >> write a bunch of code to validate the received JSON from the frontend. > > Deform does not care. > > Here's the connected pieces: > > deform.Form > - is made up of deform.Field objects > - each of which is associated with a > - colander.SchemaNode > - deform.Widget > > The form POST data is actually pre-processed by peppercorn, but you > probably don't need to think much about that. The key steps for > validation are the deserialization fo the POST data according to the > Widget hierarchy and then the validation of the resulting cstruct > against the schema hierarchy. > > The comments and code for the `deform.Field.validate` method make much > of this clear. > > If you're passing in JSON that matches your colander Schema, then you > already have the `cstruct` and just need to call `schema.deserialize` > on it.
On the other hand, if you're passing the form data in raw, as strings and with two entries for checked fields, etc, then you may want to call `form.widget.deserialize` to get your cstruct. POST data --(peppercorn)--> pstruct --(deform)--> cstruct -- (colander) --> appstruct If you're not dealing with any pre-schema transformations, such as those provided by the widgets, then you can actually skip deform altogether and just use colander. Again, `deform.Field.validate()` is a short read and shows the high level operation of all of this. -Randall -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
