"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 3 years, 2 months ago
  2. Using Textarea by joshua 6 years, 2 months ago
  3. Bulk Insert Manager by ocdcoder 2 years, 3 months ago
  4. Dynamically change a form select widget to a hidden widget by epicserve 3 years, 10 months ago
  5. Type checking templatetag filters by marcorogers 3 years, 2 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?)