I have a search form that's based off of the admin search form template:
{% load adminmedia %}
{% load i18n %}
{% if cl.search_fields %}
<div id="toolbar"><form id="changelist-search" action="." method="get">
<div><!-- DIV needed for valid HTML -->
<label for="searchbar"><img src="{% admin_media_prefix %}img/admin/icon_searchbox.png" alt="Search" /></label>
<input type="text" size="40" name="{{ SEARCH_VAR }}" value="{{ search_string|escape }}" id="searchbar" />
<input type="submit" value="{% trans 'Search' %}" />
{% if show_result_count %}
<span class="small quiet">{% blocktrans count cl.search_found_num as counter %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktrans %} (<a href="?{% if cl.is_popup %}pop=1{% endif %}">{% blocktrans with cl.search_total_num as full_result_count %}{{ full_result_count }} total{% endblocktrans %}</a>)</span>
{% endif %}
{% for pair in cl.params.items %}
{% ifnotequal pair.0 search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}"/>{% endifnotequal %}
{% endfor %}
</div>
</form></div>
<script type="text/javascript">document.getElementById("searchbar").focus();</script>
{% endif %}
When the search is submitted, the search text is passed correctly up to the query string, but unfortunately it gets rid of anything else that might have been there. For example, if I have a URL of www.example.com/?a=whatever&b=something
, after the search is submitted it becomes www.example.com/?q=searchtext
, as opposed to www.example.com/?a=whatever&b=something&q=searchtext
. I'm pretty sure the problem has something to do with the "action" attribute of the form, but I'm not well enough versed in HTML to pinpoint exactly what it should be.
Edit: problem solved, I just added hidden fields to the HTML form that preserved the values I wanted to preserve.