I have a form and a few buttons as below:
<form method="GET" novalidate id="my_form">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
</form>
<input name="page" type="hidden" form="my_form" value="1" id="submit">
<button type="submit" class="btn btn-success" form="my_form">Submit</button>
<input name="page" type="hidden" form="my_form" value="1" id="1">
<button form="my_form" role="button" class="btn btn-link">1</button>
<input name="page" type="hidden" form="my_form" value="2" id="2">
<button form="my_form" role="button" class="btn btn-link">2</button>
<input name="page" type="hidden" form="my_form" value="3" id="3">
<button form="my_form" role="button" class="btn btn-link">3</button>
As you see, I have four submit buttons. What I need is that if I pressed the submit button, the form that contains the first name and last name and the input field that adds page=1
to the GET
be submitted. If I pressed, as an example, the button 3 (the last one), the form and only the input that has page=3
be submitted not the other inputs with page=1
, page=2
, page=3
. I am using this to solve a pagination problem. How can I do this? I prefer not using JavaScript
, or if I have to, only a very simple script be used in the solution.
Please note that the number of buttons might be a lot. Actually, they are being inserted by a django template tag like:
{% for i in page_obj.paginator.page_range %}
<input name="page" type="hidden" form="my_form" value="{{i}}" id="{{i}}">