Index: docs/newforms.txt
===================================================================
--- docs/newforms.txt (revision 5243)
+++ docs/newforms.txt (working copy)
@@ -313,6 +313,30 @@
...
AttributeError: 'ContactForm' object has no attribute 'cleaned_data'
+
+Example View
+~~~~~~~~~~~~
+
+Putting this all together, here is a simple view method for the example of 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 +413,11 @@
+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 +434,10 @@
+In a template, you can invoke this if the form has been handed into the context. For example:
+
+ {{ f.as_ul }}
+
``as_table()``
~~~~~~~~~~~~~~
@@ -421,6 +454,15 @@
+In a template, you can invoke this if the form has been handed into the context. For example:
+
+ {{ f.as_table }}
+
+which is the same as
+
+ {{ f }}
+
+
Configuring HTML ``