I am using a python form which takes the values of two submit buttons and performs the next task based on which was selected.
Here's a snippet:
Template
<div class="panel-footer">
<div class="text-center">
<button type="submit" class="btn btn-success" name="submit" value="Submit">
Submit
</button>
<button type="submit" class="btn btn-custom" name="addanother" id="addanother">
Submit & Add Another
</button>
<button type="submit" class="btn btn-default" onclick="history.go(-1);return false;">
Cancel
</button>
</div>
</div><!-- Panel Footer -->
View
if request.method == "POST":
form = AddUserForm(request.POST)
if form.is_valid():
#do function
if 'submit' in request.POST:
return HttpResponseRedirect(reverse("userdetail", args=(new_user.id,)))
elif 'addanother' in request.POST:
return HttpResponseRedirect(reverse("adduser",))
The problem I have is that this form does not redirect when the 'addanother' button is clicked. (The form still submits though.)
Quick Fix
I have managed to do quick fix this issue by replacing:
elif 'addanother' in request.POST:
with:
else:
But this is still an issue as I plan on using more than two submit buttons in the forms following on from this one.
Has anyone came across this before and know what the issue is?
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire