0

Now I'm making a web app with django. I want to put more than 2 query paramaters into my URL, but if I put some keywords into my search box and send them, the query paramater will show only these keywords. For example, current URL is like below. https://example.com/jobs?area=SYDNEY If I search something, it becomes below. https://example.com/jobs?query=something

This is not what I want. What I want is https://example.com/jobs?area=SYDNEY&query=something

How can I do it?

<form action="" method="get">
    <input type="text" name="query" value="{{ request.GET.query }}"><input type="submit" value="Search">
</form>
Light
  • 31
  • 5
  • Remove form `action`, collect the input parameters and then use `fetch` or `XMLHttpRequest` to send the http request asynchronously. Examples of fetch here: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch – Abrar Hossain Jul 05 '22 at 02:49
  • Does this answer your question? [When submitting a GET form, the query string is removed from the action URL](https://stackoverflow.com/questions/1116019/when-submitting-a-get-form-the-query-string-is-removed-from-the-action-url) – Abdul Aziz Barkat Jul 05 '22 at 04:37

1 Answers1

1

You can use the same method you used to get the query value in your form to get the area value, then put it into a hidden field

<form action="" method="get">
    <input type="text" name="query" value="{{ request.GET.query }}"><input type="submit" value="Search">
    <input type="hidden" name="area" value="{{ request.GET.area }}">
    <input type="submit" value="Search">
</form>

Now the hidden field is populated from the URL, and passed along as part of the form when it's submitted

SamSparx
  • 4,629
  • 1
  • 4
  • 16