[<<] Industrie Toulouse
Late last night, I finally got Formulator under control. This happened after deciding to take a different approach to it - instead of trying to come up with a generic all-singing automatic form generating template, I took some forms I had started work on in GoLive, and used tal:replace on individual elements directly. Now, I still have my ability to mock up in "GoLive", combined with the ability to use Formulator's validation services.

A quick example:


<div class="warning"
     tal:condition="options/errors/registration|nothing">
 ... loop through validation errors here...
</div>
<form action="register.py" method="post"
      tal:define="form here/form_Register">
 Full Name:
 <input type="text" name="fullname" size="29"
        tal:replace="structure python:form.fullname.render(REQUEST=request)">
etc... </form>

Using this technique, I was actually able to use two Formulator Form objects within a single HTML form - one handling registration details, one handling address details (which is expected to be used quite a bit in the site). The target Python script looks something like this:

request = container.REQUEST
errors = []
try: context.form_Register.validate_all_to_request(request)
except FormValidationError, e:
    ## 'e' is an exception instance with a sequence of 
    ## validation errors
    errors.extend(e.errors)
 
try: context.form_Address.validate_all_to_request(request)
except FormValidationError, e:
    ## Now extend the list of errors with Address validation errors
    errors.extend(e.errors)
 
if errors:
    ## put the errors list in a dictionary in to distinguish which
    ## form the errors may have came from.
    return context['register.html'](request, errors={'registration':errors})

There's still one area where I have problems with Formulator, and that's in <select> .. <option> widget generation. I seem to use different option values and contents (<option value="VA">Virginia</option>) quite a bit in my sites, especially since Page Templates have made generating these even easier than in DTML. But I've had a hard time figuring out (a) how to even generate these types of option tags in Formulator (usually based off of the result of some script/method), and (b) how to do the equality "selected" testing when using a form on an existing object with a set value. It may be possible with stock Formulator, but it hasn't been obvious.

On the public side of this site, Form Validation is going to be critical. It's nice not to have to roll-my-own solution yet again.