djangosnippets.org: Latest snippets tagged with 'hidden'https://djangosnippets.org/tags/hidden/2009-12-13T23:30:23.688142-06:00Prevent form tampering of hidden fields
2009-12-13T23:30:23.688142-06:00thejuhttps://djangosnippets.org/snippets/1835/<p>Sometimes, we need to pass hidden fields with an initial value in forms but cannot trust the returned values because it could have been tampered.</p>
<p>So here is a form that adds an additional 'hidden' field (called 'form_hash') that hashes all the initial value of hidden fields and checks for …</p>
Freely redistributableField value as plain text which can't be edited by user
2009-09-29T07:32:10.736072-05:00szczavvhttps://djangosnippets.org/snippets/1746/<p>Shows field value as plain text which can't be edited by user. Field value (or key value for foreign keys) is stored in hiddden input.</p>
<p>Value of field is stored in hidden input and current value is placed as plain text. User can't change it's value. If field is foreign …</p>
Freely redistributableDynamically change a form select widget to a hidden widget
2009-07-01T18:01:13.679887-05:00epicservehttps://djangosnippets.org/snippets/1610/<p>This is an example of how you change a ChoiceField select widget into a hidden field if the right GET variable is passed. In this example code it would change the select widget into something like the following if something like "?d=3" was passed.</p>
<p><code><p><label for="id_designation">Designation</label>Designation Option<input type="hidden" name="designation" value="3" …</code></p>
Freely redistributable"Dynamic" form with a hidden field
2009-03-25T03:26:42.491118-05:00flaxterhttps://djangosnippets.org/snippets/1394/<p>This code demonstrates two simple techniques:
</p>
<ol>
<li><p>so-called "dynamic" forms, in which the form is created at run time by the model
</p>
</li>
<li><p>using a widget (forms.widgets.HiddenInput) for a field of the form. I feel like this could be highlighted more in the documentation. You need to do something similar to get …</p></li></ol>
Freely redistributableTamper safe HiddenFields
2008-11-13T09:04:12.185779-06:00alexmeiselhttps://djangosnippets.org/snippets/1184/<p>This snippet prevents people from tampering with the data in hidden form fields. This is something you usually want unless you have some Javascript Vodoo going on on the browser side.</p>
<p>For the people scratching their heads:</p>
<p>This form class will dynamically create a clean function for every passed additional …</p>
Freely redistributableHidden Forms
2007-07-14T10:40:41.809290-05:00insinhttps://djangosnippets.org/snippets/316/<p>Have your forms descend from this BaseForm if you need to be able to render a valid form as hidden fields for re-submission, e.g. when showing a preview of something generated based on the form's contents.
</p>
<p>Custom form example:
</p>
<pre><code>>>> from django import newforms as forms
>>> class MyForm(HiddenBaseForm, forms.Form): …</code></pre>
Freely redistributable