Joseph Kocherhans wrote: > > form = ContactForm() > if request.method == POST and form.bind(request.POST): > send_email_and_redirect() > return render_to_response('email_form.html', {'form':form}) > > Assumptions: form.bind(data) does *not* return a BoundForm. bind does > the validation and probably populates form.errors or .errors() or > whatever. bind returns True or False depending on whether validation > succeeded or not. bind does not short circuit on the first error. > > Validation happens only once, in the bind call. It's not entirely > obvious that a method called bind would return a boolean depending on > the success of validation, but examples and docs should clear that up > that I think. Maybe this is being too clever to save a couple of lines > or a few milliseconds though.
(I'm not an official "dev" so I hope it's not considered inappropriate of me to provide my feedback.) Instead of the assumption that bind() validates, why not have an is_valid() method that assumes binding of the Form. To me this is a more appropriate assumption since you have to bind the form to validate it. And it leaves some flexibility open so you can bind forms and not yet validate -- say if you want to bind and do some other form actions and then validate. Example... form = ShoppingForm() if request.method == POST and form.is_valid(request.POST): ... Or... form = ShoppingForm() if request.method == POST: form.bind(request.POST) if form.billing_same_as_shipping == True: # Copy billing info to shipping form.shipping = form.billing if form.is_valid(): ... The access methods for "form.shipping" probably aren't appropriate, but just making a use case for extra manipulation of form data before validation. -Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---