diff --git a/docs/newforms.txt b/docs/newforms.txt index ed43670960..4d2400afcc 100644 --- a/docs/newforms.txt +++ b/docs/newforms.txt @@ -313,6 +313,31 @@ record, here's what happens with unbound forms:: ... AttributeError: 'ContactForm' object has no attribute 'cleaned_data' + +Example View +~~~~~~~~~~~~ + +Putting this all together, here is a simple view method that uses our contact +form:: + + from django.shortcuts import render_to_response + from django import newforms as forms + + class ContactForm(forms.Form): + subject = forms.CharField(max_length=100) + message = forms.CharField() + sender = forms.EmailField() + cc_myself = forms.BooleanField() + + def contact(request): + if request.POST: + f = ContactForm(request.POST) + if f.is_valid: + # ... do something with f.cleaned_data + else: + f = ContactForm() + return render_to_response('contact.html', {'form': f}) + Outputting forms as HTML ------------------------ @@ -389,6 +414,12 @@ containing one field::

+In a template, you can invoke this if the form has been handed into the +context. For example:: + + {{ f.as_p }} + + ``as_ul()`` ~~~~~~~~~~~ @@ -405,6 +436,11 @@ so that you can specify any HTML attributes on the ``