I have this form:
class CollaboratorForm(forms.Form):
user = forms.CharField(label="Username",max_length=100)
canvas = forms.IntegerField(widget=forms.HiddenInput)
....
def clean_user(self):
user = self.cleaned_data['user']
canvas = self.cleaned_data['canvas']
In the view I'm simply calling
if form.is_valid():
I get the error:
KeyError at /canvas/1/add-collaborator/
'canvas'
According to firebug the value is posting, it's just doesn't seem to be making it to my clean function. Am I doing it wrong?
EDIT: Post data
canvas 1
csrfmiddlewaretoken 2cb73be791b32ca9a41566082c804312
user username
EDIT2: I would also be willing to take an answer that could tell me how to send the primary key to the clean_user function, where the primary key is the /1/ in the example url above. The function in the view that is called is:
def canvas_add_collaborator(request, pk):
So I would want to send the pk to the clean_user function which would solve my problem by not needing the hidden field.
cleaned_data is where all validated fields are stored.
How do Hidden Fields work? Hidden Fields allows you to place data that you already have directly in your typeform URL. You can view all your data in the Results panel.
A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted. A hidden field often stores what database record that needs to be updated when the form is submitted.
GET and POSTDjango's login form is returned using the POST method, in which the browser bundles up the form data, encodes it for transmission, sends it to the server, and then receives back its response. GET , by contrast, bundles the submitted data into a string, and uses this to compose a URL.
You need to change the method name to clean(), not clean_user(). 'canvas' is not in the cleaned_data if you are just validating the user field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With