Index: docs/newforms.txt
===================================================================
--- docs/newforms.txt (revision 5174)
+++ docs/newforms.txt (working copy)
@@ -286,6 +286,30 @@
...
AttributeError: 'ContactForm' object has no attribute 'clean_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.clean_data
+ else:
+ f = ContactForm()
+ return render_to_response('contact.html', {'form': f})
+
Outputting forms as HTML
------------------------
@@ -362,6 +386,11 @@
+In a template, you can invoke this if the form has been handed into the context. For example:
+
+ {{ f.as_p }}
+
+
``as_ul()``
~~~~~~~~~~~
@@ -378,6 +407,10 @@
+In a template, you can invoke this if the form has been handed into the context. For example:
+
+ {{ f.as_ul }}
+
``as_table()``
~~~~~~~~~~~~~~
@@ -394,6 +427,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 ``