Forms

Enamel provides a wrapper on Formal. This wrapper is simply a 'from formal import *' in enamel.form. The default pages classes automatically perform the multiple inheritance of Formal mixins in the correct order etc to make their use instantaneous when you decide it.

Here is an example of creating a simple from and attaching and action to it.

class CreateUser(pages.Standard):
    def form_addUser(self, data):
        addUser = form.Form()
        addUser.addField('name', form.String(), label = "Username")
        addUser.addField('password', form.String(), form.CheckedPassword, label = "Password")

        addUser.addAction(self.addUser)
        return addUser

    def addUser(self, context, f, data):
        # data returned from a form is in Unicode.
        self.enamel.storage.addUser(
            data['name'].encode(),
            sha.sha(data['password'].encode()).hexdigest()
        )
        return url.root

    def body(self):
        return tags.directive('form addUser')

tags.directive is used to render the form in Stan. It can be nested anywhere in a Stan object.