"Dynamic" form with a hidden field

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from django import forms

hiddenValues = forms.Form()

value0 = 17

hiddenValues.fields['value0'] = forms.CharField(initial=value0, 
  widget=forms.widgets.HiddenInput())

# pass the form to your template
# render it as you like, e.g. with form.as_p

More like this

  1. Complex Formsets, Redux by smagala 1 year, 11 months ago
  2. Using Textarea by joshua 4 years, 11 months ago
  3. Dynamically change a form select widget to a hidden widget by epicserve 2 years, 7 months ago
  4. Dynamic Template Loader by jgeewax 3 years, 7 months ago
  5. Type checking templatetag filters by marcorogers 1 year, 11 months ago

Comments

tommy (on August 5, 2010):

Great tip. Works like a charm.

#

gamesbook (on April 9, 2011):

Not sure what the author means about documentation for widgets - they are extensively documented here:

http://docs.djangoproject.com/en/dev/ref/forms/fields/#widget

and here:

http://docs.djangoproject.com/en/dev/ref/forms/widgets/

#

(Forgotten your password?)