<p>To get this working, you will need to find a way to continue passing all of your form’s values to each of the additional pages.</p>

<p>There are a few ways you could do that, but the easiest and best option is to change your search form’s <code>method</code> attribute to <code>"get"</code> rather than <code>"post"</code>.</p>

<pre><code>&lt;form method="get"&gt;
</code></pre>

<p><em>(Side note: there’s no need to add <code>action=""</code> – the default browser behavior if that attribute is omitted is for the form to submit to the current URL.)</em></p>

<p>Now when you submit your form you will see all of the form values show up in the resulting page’s query string. While that’s not quite as nice-looking, its advantages outweigh the ugly: browsers won’t ask users if they are sure they want to resubmit a form when they click the Back/Forward buttons, and the URLs will be sharable.</p>

<p>The next step is to update your pagination links to include the query string, which will effectively pass on the form’s values between each of the pages. We’ll use <a href="http://buildwithcraft.com/docs/templating/craft.request#getQueryStringWithoutPath">craft.request.getQueryStringWithoutPath()</a> for that:</p>

<pre><code>{% set qs = '?' ~ craft.request.getQueryStringWithoutPath() %}

&lt;li&gt;&lt;a href="{{ paginate.firstUrl ~ qs }}" title="First Page"&gt;&amp;laquo;&lt;/a&gt;&lt;/li&gt;
{% if paginate.prevUrl %}
   &lt;li&gt;&lt;a href="{{ paginate.prevUrl ~ qs }}" title="Previous Page"&gt;&amp;lsaquo;&lt;/a&gt;&lt;/li&gt;
{% endif %}
{% for page, url in paginate.getPrevUrls(4) %}
   &lt;li&gt;&lt;a href="{{ url ~ qs }}" title="Page {{ page }}"&gt;{{ page }}&lt;/a&gt;
{% endfor %}
&lt;li class="current"&gt;&lt;a href="" title="Page {{ paginate.currentPage }}"&gt;{{ paginate.currentPage }}&lt;/a&gt;&lt;/li&gt;
{% for page, url in paginate.getNextUrls(4) %}
   &lt;li&gt;&lt;a href="{{ url ~ qs }}" title="Page {{ page }}"&gt;{{ page }}&lt;/a&gt;
{% endfor %}
{% if paginate.nextUrl %}
   &lt;li&gt;&lt;a href="{{ paginate.nextUrl ~ qs }}" title="Next Page"&gt;&amp;rsaquo;&lt;/a&gt;&lt;/li&gt;
{% endif %}
&lt;li&gt;&lt;a href="{{ paginate.lastUrl ~ qs }}" title="Last Page"&gt;&amp;raquo;&lt;/a&gt;&lt;/li&gt;
</code></pre>

CC BY-SA 3.0
2015-01-27T18:34:06.270Z
2015-01-27T18:34:06.270Z
Brandon Kelly
<p>I have a search form containing 1 text field and 2 checkbox groups.</p>

<p>Text field is called: <code>keywords</code> and the checkbox groups are called: <code>services[]</code> and <code>locations[]</code>.</p>

<p>The search works fine if I don't try to pagination the results.</p>

<p>When I try to paginate the results, say I set the limit to 9 entries per page, my first page has the 9 entries listed and I get next page link to go to page 2 but when I click the next page link, I don't get the 2nd page as expected. The results have cleared? Page "reset".</p>

<p>How can I paginate my form containing multiple fields?</p>

<p>I have already tried <code>craft.request.getQueryStringWithoutPath()</code>, the "solution" in another question but it does not work for me with checkbox groups as my 2 other form fields.</p>

<p>Here is my code:</p>

<pre><code>{% set services = craft.categories.group("services").status("live").find() %}
{% set locations = craft.categories.group("locations").status("live").find() %}

{% set queryKeywords = craft.request.getParam("keywords") | trim %}
{% set queryServices = craft.request.getParam("services") %}
{% set queryLocations = craft.request.getParam("locations") %}

&lt;form action="" method="POST"&gt;
    &lt;input type="text" name="keywords" value=""&gt;
    {% if services | length %}
        {% for service in services %}
        &lt;label&gt;{{ service.title }}&lt;input type="checkbox" name="services[]" value="{{ service.slug }}" /&gt;&lt;/label&gt;
        {% endfor %}
    {% endif %}
    {% if locations | length %}
        {% for location in locations %}
        &lt;label&gt;{{ location.title }} &lt;input type="checkbox" name="locations[]" value="{{ location.slug }}"/&gt;&lt;/label&gt;                                     
        {% endfor %}
    {% endif %}
    &lt;button type="submit"&gt;Refine&lt;/button&gt;
&lt;/form&gt;




{% set originalKeywords = craft.request.getParam("keywords") | trim %}
{% set keywords = originalKeywords | replace({ "*" : "" }) %}
{% set services = craft.request.getParam("services") %}
{% set locations = craft.request.getParam("locations") %}

{% if (keywords | length) or (services | length) or (locations | length) %}
    {% set relatedTo = ["and"] %}


    {% set serviceCategoryIds = [] %}
    {% set locationCategoryIds = [] %}


    {% set serviceCategories = craft.categories.group("services") %}
    {% set locationCategories = craft.categories.group("locations") %}


    {% set servicesCategories = services | join(", ") | trim %}
    {% if services | length %}
        {% for service in services %}
            {% set serviceCategoryIds = serviceCategories.slug(servicesCategories).ids() %}
        {% endfor %}
    {% endif %}
    {% if serviceCategoryIds | length %}
        {% for serviceCategoryId in serviceCategoryIds %}
            {% set relatedTo = relatedTo | merge([serviceCategoryId]) %}
        {% endfor %}
    {% endif %}


    {% set locationsCategories = locations | join(", ") | trim %}
    {% if locations | length %}
        {% for location in locations %}
            {% set locationCategoryIds = locationCategories.slug(locationsCategories).ids() %}
        {% endfor %}
    {% endif %}
    {% if locationCategoryIds | length %}
        {% for locationCategoryId in locationCategoryIds %}
            {% set relatedTo = relatedTo | merge([locationCategoryId]) %}
        {% endfor %}
    {% endif %}


    {% set keywords = "*" ~ keywords | replace({ " " : "* *" }) ~ "*" %}


    {% set allMembers = craft.users.group("members").status("live").search(keywords).order("score") %}


    {% if (relatedTo | length) &gt; 1 %}
        {% set allMembers = allMembers.relatedTo(relatedTo) %}
    {% endif %}


    &lt;h3&gt;{{ allMembers | length }} Result{% if (allMembers | length) == 1 %}{% else %}s{% endif %}&lt;/h3&gt;


    {% if allMembers | length %}
        {% paginate allMembers as members %}

            &lt;ul&gt;
                {% for member in members %}
                &lt;li&gt;{{ member.fullName }}&lt;/li&gt;
                {% endfor %}
            &lt;/ul&gt;

            {% if paginate.totalPages &gt; 1 %}
            &lt;ul&gt;
                &lt;li&gt;&lt;a href="{{ paginate.firstUrl }}" title="First Page"&gt;&amp;laquo;&lt;/a&gt;&lt;/li&gt;
                {% if paginate.prevUrl %}&lt;li&gt;&lt;a href="{{ paginate.prevUrl }}" title="Previous Page"&gt;&amp;lsaquo;&lt;/a&gt;&lt;/li&gt;{% endif %}
                {% for page, url in paginate.getPrevUrls(4) %}
                &lt;li&gt;&lt;a href="{{ url }}" title="Page {{ page }}"&gt;{{ page }}&lt;/a&gt;
                {% endfor %}
                &lt;li class="current"&gt;&lt;a href="" title="Page {{ paginate.currentPage }}"&gt;{{ paginate.currentPage }}&lt;/a&gt;&lt;/li&gt;
                {% for page, url in paginate.getNextUrls(4) %}
                &lt;li&gt;&lt;a href="{{ url }}" title="Page {{ page }}"&gt;{{ page }}&lt;/a&gt;
                {% endfor %}
                {% if paginate.nextUrl %}&lt;li&gt;&lt;a href="{{ paginate.nextUrl }}" title="Next Page"&gt;&amp;rsaquo;&lt;/a&gt;&lt;/li&gt;{% endif %}
                &lt;li&gt;&lt;a href="{{ paginate.lastUrl }}" title="Last Page"&gt;&amp;raquo;&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
            {% endif %}

        {% endpaginate %}

    {% else %}
        &lt;p&gt;Your search didn&amp;#39;t return any members.&lt;/p&gt;
    {% endif %}

{% endif %}
</code></pre>

CC BY-SA 3.0
2015-01-20T08:09:02.733Z
Marion, the question titled "How to paginate search results?" only uses a query param. My question is related to using a form with multiple fields so the solution in "How to paginate search results?" doesn't work for me.
Sean Delaney
CC BY-SA 3.0
2015-01-20T17:54:41.537Z
Hi Sean, can you edit your question and add some of your existing code? That will help us figure out exactly what needs to be changed, and also shed some light as to why this question is not a duplicate.
Lindsey D
CC BY-SA 3.0
2015-01-22T09:31:36.777Z
I've added my existing code. My question is not a duplicate. Is are no other questions posted that has 3 form fields and paginates that search results. All previous posts only have 1 form field and the solutions in those questions don't work for me.
Sean Delaney
CC BY-SA 3.0
2015-01-27T10:33:23.727Z
Guys, please read my comments above - the solutions in these other questions do not work for me. Why are you still marking this question as a duplicate! Can you please explain why? All I want is a solution to **my issue**, which are **not** the same as these other questions! These other solutions only use 1 form field, I am using 3 form fields and pagination is not working.
Sean Delaney
CC BY-SA 3.0
2015-01-27T11:05:44.467Z
It's very frustrating when everyone jumps on the "duplicate" bandwagon. It's like no one is fully reading my question and comments, realising the difference between mine and this other question (http://craftcms.stackexchange.com/questions/644/how-to-paginate-search-results).
Sean Delaney
CC BY-SA 3.0
2015-01-27T11:26:16.027Z
This is clearly not the same problem, please read the question properly before marking as a duplicate.
Ian Nebbiolo
CC BY-SA 3.0
2015-01-27T16:07:27.703Z
Sean, what's the URL you are getting on page 2 for `{% paginate entries.limit(9) as paginatedEntries %}` and a link `<a href="{{ paginate.nextUrl }}?{{ craft.request.getQueryStringWithoutPath() }}">&rsaquo;</a>`?
carlcs
CC BY-SA 3.0
2015-01-27T16:21:58.270Z
Ahhh... you're sending the form data using `method="POST"`. This can't work with the suggested "solutions". Remove this or change to `method="GET"` as a temporary fix.
carlcs
CC BY-SA 3.0
2015-01-27T17:38:52.520Z
@SeanDelaney Don't get too frustrated... everyone is doing what they can on a site like this. It can be challenging to follow the minutia of a question's specific details because we can't see the code and aren't absorbing all the details.
Anna_MediaGirl
<pagination>
Search Results Pagination with multiple form fields
# Search Results Pagination with multiple form fields

(Asked by: username_0 on 2015-01-19)

I have a search form containing 1 text field and 2 checkbox groups.
Text field is called: keywords and the checkbox groups are called: services[] and locations[].
The search works fine if I don't try to pagination the results.
When I try to paginate the results, say I set the limit to 9 entries per page, my first page has the 9 entries listed and I get next page link to go to page 2 but when I click the next page link, I don't get the 2nd page as expected. The results have cleared? Page "reset".
How can I paginate my form containing multiple fields?
I have already tried craft.request.getQueryStringWithoutPath(), the "solution" in another question but it does not work for me with checkbox groups as my 2 other form fields.
Here is my code:
{% set services = craft.categories.group("services").status("live").find() %}
{% set locations = craft.categories.group("locations").status("live").find() %}

{% set queryKeywords = craft.request.getParam("keywords") | trim %}
{% set queryServices = craft.request.getParam("services") %}
{% set queryLocations = craft.request.getParam("locations") %}


    
    {% if services | length %}
        {% for service in services %}
        {{ service.title }}
        {% endfor %}
    {% endif %}
    {% if locations | length %}
        {% for location in locations %}
        {{ location.title }}                                      
        {% endfor %}
    {% endif %}
    Refine





{% set originalKeywords = craft.request.getParam("keywords") | trim %}
{% set keywords = originalKeywords | replace({ "*" : "" }) %}
{% set services = craft.request.getParam("services") %}
{% set locations = craft.request.getParam("locations") %}

{% if (keywords | length) or (services | length) or (locations | length) %}
    {% set relatedTo = ["and"] %}


    {% set serviceCategoryIds = [] %}
    {% set locationCategoryIds = [] %}


    {% set serviceCategories = craft.categories.group("services") %}
    {% set locationCategories = craft.categories.group("locations") %}


    {% set servicesCategories = services | join(", ") | trim %}
    {% if services | length %}
        {% for service in services %}
            {% set serviceCategoryIds = serviceCategories.slug(servicesCategories).ids() %}
        {% endfor %}
    {% endif %}
    {% if serviceCategoryIds | length %}
        {% for serviceCategoryId in serviceCategoryIds %}
            {% set relatedTo = relatedTo | merge([serviceCategoryId]) %}
        {% endfor %}
    {% endif %}


    {% set locationsCategories = locations | join(", ") | trim %}
    {% if locations | length %}
        {% for location in locations %}
            {% set locationCategoryIds = locationCategories.slug(locationsCategories).ids() %}
        {% endfor %}
    {% endif %}
    {% if locationCategoryIds | length %}
        {% for locationCategoryId in locationCategoryIds %}
            {% set relatedTo = relatedTo | merge([locationCategoryId]) %}
        {% endfor %}
    {% endif %}


    {% set keywords = "*" ~ keywords | replace({ " " : "* *" }) ~ "*" %}


    {% set allMembers = craft.users.group("members").status("live").search(keywords).order("score") %}


    {% if (relatedTo | length) > 1 %}
        {% set allMembers = allMembers.relatedTo(relatedTo) %}
    {% endif %}


    {{ allMembers | length }} Result{% if (allMembers | length) == 1 %}{% else %}s{% endif %}


    {% if allMembers | length %}
        {% paginate allMembers as members %}

            
                {% for member in members %}
                {{ member.fullName }}
                {% endfor %}
            

            {% if paginate.totalPages > 1 %}
            
                «
                {% if paginate.prevUrl %}‹{% endif %}
                {% for page, url in paginate.getPrevUrls(4) %}
                {{ page }}
                {% endfor %}
                {{ paginate.currentPage }}
                {% for page, url in paginate.getNextUrls(4) %}
                {{ page }}
                {% endfor %}
                {% if paginate.nextUrl %}›{% endif %}
                »
            
            {% endif %}

        {% endpaginate %}

    {% else %}
        Your search didn't return any members.
    {% endif %}

{% endif %}

**Tags:** pagination
> **Comments:**
> **username_0**: Marion, the question titled "How to paginate search results?" only uses a query param. My question is related to using a form with multiple fields so the solution in "How to paginate search results?" doesn't work for me.  
> **username_1**: Hi Sean, can you edit your question and add some of your existing code? That will help us figure out exactly what needs to be changed, and also shed some light as to why this question is not a duplicate.  
> **username_0**: I've added my existing code. My question is not a duplicate. Is are no other questions posted that has 3 form fields and paginates that search results. All previous posts only have 1 form field and the solutions in those questions don't work for me.  
> **username_0**: Guys, please read my comments above - the solutions in these other questions do not work for me. Why are you still marking this question as a duplicate! Can you please explain why? All I want is a solution to **my issue**, which are **not** the same as these other questions! These other solutions only use 1 form field, I am using 3 form fields and pagination is not working.  
> **username_0**: It's very frustrating when everyone jumps on the "duplicate" bandwagon. It's like no one is fully reading my question and comments, realising the difference between mine and this other question (http://craftcms.stackexchange.com/questions/644/how-to-paginate-search-results).  
> **username_2**: This is clearly not the same problem, please read the question properly before marking as a duplicate.  
> **username_3**: Sean, what's the URL you are getting on page 2 for `{% paginate entries.limit(9) as paginatedEntries %}` and a link `<a href="{{ paginate.nextUrl }}?{{ craft.request.getQueryStringWithoutPath() }}">&rsaquo;</a>`?  
> **username_3**: Ahhh... you're sending the form data using `method="POST"`. This can't work with the suggested "solutions". Remove this or change to `method="GET"` as a temporary fix.  
> **username_4**: @SeanDelaney Don't get too frustrated... everyone is doing what they can on a site like this. It can be challenging to follow the minutia of a question's specific details because we can't see the code and aren't absorbing all the details.  

---

## 1 answers

### Answer by username_5 on 2015-01-27. Score: 5 | Accepted answer

To get this working, you will need to find a way to continue passing all of your form’s values to each of the additional pages.
There are a few ways you could do that, but the easiest and best option is to change your search form’s method attribute to "get" rather than "post".


(Side note: there’s no need to add action="" – the default browser behavior if that attribute is omitted is for the form to submit to the current URL.)
Now when you submit your form you will see all of the form values show up in the resulting page’s query string. While that’s not quite as nice-looking, its advantages outweigh the ugly: browsers won’t ask users if they are sure they want to resubmit a form when they click the Back/Forward buttons, and the URLs will be sharable.
The next step is to update your pagination links to include the query string, which will effectively pass on the form’s values between each of the pages. We’ll use craft.request.getQueryStringWithoutPath() for that:
{% set qs = '?' ~ craft.request.getQueryStringWithoutPath() %}

«
{% if paginate.prevUrl %}
   ‹
{% endif %}
{% for page, url in paginate.getPrevUrls(4) %}
   {{ page }}
{% endfor %}
{{ paginate.currentPage }}
{% for page, url in paginate.getNextUrls(4) %}
   {{ page }}
{% endfor %}
{% if paginate.nextUrl %}
   ›
{% endif %}
»


---

