Hello.
I have written custom constructor for a form, the whole form class looks like this:
class UploadForm(forms.Form):
file = forms.FileField(label = "Plik")
def __init__(self, coto, naglowek, *args, **kwargs):
super(UploadForm, self).__init__(*args, **kwargs)
self.coto = coto
self.naglowek = naglowek
When submitting form, in my view, I have something like
if request.method == 'POST':
form = UploadForm(request.POST, request.FILES)
if form.is_valid():
add_form(request.FILES['file'])
return HttpResponseRedirect('uploaded/')
The problem is, that when I am creating form in this way in my view, I am not passing coto and naglowek, so when I am calling form.is_valid() --> it returns false.
The template which passess it looks like:
<table class="uploadform">
<form action="." method="POST" enctype="multipart/form-data">
{% for form in forms %}
<tr>
<td>{{ form.naglowek }}</td>
<td>{{ form.file }}</td>
<td><input type="submit" name="{{ form.coto }}" id="{{ form.coto }}" value="Wyślij"></td>
</tr>
{% endfor %}
</form>
</table>
I would be grateful for any suggestions.
[EDIT] I might not say this clearlly enough, but I will try my best:
When I am submitting this form, in view, I need to know which submit button was pressed - I have many of them assigned to single form. From what I know, when I am assigning id to submit button, it should be availible in post, right? The trick is, that it is not availible.
I have two questions: * What needs to be done, If I want to know which submit button was pressed? Is assigning the name the only way? * Is there any error in my logic?