Django Form with multiple buttons
I have a form for a voting system. I have the candidates in a table row. At the end of the row I have button with the candidate ID
<form method="post">
<table>
...
<tr>
<td>name</td>
<td>campaign promises</td>
<td><button id="candidate_id"></td>
<tr>
...
</table>
</form>
"candidate_id" is an actual number and unique. I would like to get that id value from the post request, so I know which candidate was selected. Im hoping its as simple as
request.POST.Something
Yes, you can provide name
attribute to the button, say for example candidate_id_value
as:
<form method="POST">
<table>
...
<tr>
<td>name</td>
<td>campaign promises</td>
<td><button id="candidate_id" name="candidate_id_value" ></td>
<tr>
...
</table>
</form>
Then access this value in the view as:
request.POST.get("candidate_id_value",False)