Passing multiple values to a parameter

developertools
hubdb

#1

I have this page set up with 3 sets of filters and passing the filtered values to the URL; however, I would like to see if it’s possible to pass multiple values to a single parameter. For example, to select multiple categories and passing the selected values to the URL.

http://saintleo.hs-sites.com/test-query

This is what the code looks like:

<div class="filter-wrap">
    <div class="clear-all"><a href="/test-query?category=&degree_level=&modality=">Clear All Filters</a></div>
    <form id="form_id" method="get">
        <h3>Category</h3>
        <ul class="category-list">
            {% set cats = hubdb_table_column(676329, "category").options %}
            <li><input type="radio" name="category" id="cat_all" value="" onChange="this.form.submit()"><label for="cat_all">All School</label>
            {% for choice in cats %}
                {% set cat_list = cat_list~choice.id|list %}
                {% if choice.id == request.query_dict.category %}
                    <li><input type="radio" name="category" id="cat_{{ choice.name|lower|replace(' ', '-') }}" value="{{ choice.id }}" onChange="this.form.submit()" checked><label for="cat_{{ choice.name|lower|replace(' ', '-') }}">{{ choice.name }}</label>
                {% else %}
                    <li><input type="radio" name="category" id="cat_{{ choice.name|lower|replace(' ', '-') }}" value="{{ choice.id }}" onChange="this.form.submit()"><label for="cat_{{ choice.name|lower|replace(' ', '-') }}">{{ choice.name }}</label>
                {% endif %}
            {% endfor %}
        </ul>
        <h3>Degree Level</h3>
        <ul class="degree-list">
            {% set degs = hubdb_table_column(676329, "degree_level").options %}
            <li><input type="radio" name="degree_level" id="deg_all" value="" onChange="this.form.submit()"><label for="deg_all">All Degree Levels</label>
            {% for choice in degs %}
                {% set deg_list = deg_list~choice.id|list %}
                {% if choice.id == request.query_dict.degree_level %}
                    <li><input type="radio" name="degree_level" id="cat_{{ choice.name|lower|replace(' ', '-') }}" value="{{ choice.id }}" onChange="this.form.submit()" checked><label for="cat_{{ choice.name|lower|replace(' ', '-') }}">{{ choice.name }}</label>
                {% else %}
                    <li><input type="radio" name="degree_level" id="cat_{{ choice.name|lower|replace(' ', '-') }}" value="{{ choice.id }}" onChange="this.form.submit()"><label for="cat_{{ choice.name|lower|replace(' ', '-') }}">{{ choice.name }}</label>
                {% endif %}
            {% endfor %}
        </ul>
        <h3>Location</h3>
        <ul class="location-list">
            {% set locs = hubdb_table_column(676329, "modality").options %}
            <li><input type="radio" name="modality" id="loc_all" value="" onChange="this.form.submit()"><label for="loc_all">All Locations</label>
            {% for choice in locs %}
                {% set loc_list = loc_list~choice.id|list %}
                {% if choice.id == request.query_dict.modality %}
                    <li><input type="radio" name="modality" id="loc_{{ choice.name|lower|replace(' ', '-') }}" value="{{ choice.id }}" onChange="this.form.submit()" checked><label for="loc_{{ choice.name|lower|replace(' ', '-') }}">{{ choice.name }}</label>
                {% else %}
                    <li><input type="radio" name="modality" id="loc_{{ choice.name|lower|replace(' ', '-') }}" value="{{ choice.id }}" onChange="this.form.submit()"><label for="loc_{{ choice.name|lower|replace(' ', '-') }}">{{ choice.name }}</label>
                {% endif %}
            {% endfor %}
        </ul>
    </form>
</div>


{% set cat_queryparam = "" %}
{% set deg_queryparam = "" %}
{% set loc_queryparam = "" %}
{% set queryparam = "" %}

{# -------------------- CATEGORIES -------------------- #}
{% if request.query_dict.category == "" %}
    {% set cat_queryparam = "" %}
    <script>$("#cat_all").prop('checked', true);</script>
{% endif %}
{% if request.query_dict.category in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"] %}
    {% set cat_queryparam = cat_queryparam ~ "&category="~request.query_dict.category|urlencode %}
{% endif %}

{# -------------------- DEGREE LEVELS -------------------- #}
{% if request.query_dict.degree_level == "" %}
    {% set deg_queryparam = "" %}
    <script>$("#deg_all").prop('checked', true);</script>
{% endif %}
{% if request.query_dict.degree_level in ["1", "2", "3", "4", "5", "6", "7"] %}
    {% set deg_queryparam = deg_queryparam ~ "&degree_level="~request.query_dict.degree_level|urlencode %}
{% endif %}

{# -------------------- LOCATIONS -------------------- #}
{% if request.query_dict.modality == "" %}
    {% set loc_queryparam = "" %}
    <script>$("#loc_all").prop('checked', true);</script>
{% endif %}
{% if request.query_dict.modality in ["1", "2", "3"] %}
    {% set loc_queryparam = loc_queryparam ~ "&modality="~request.query_dict.modality|urlencode %}
{% endif %}

{% set queryparam = cat_queryparam ~ deg_queryparam ~ loc_queryparam %}

Thanks in advance for any assistance!


#2

Yes, using a Multiselect column, you can use the contains filter to find rows that match any selection. See https://developers.hubspot.com/docs/methods/hubdb/get_table_rows.


#3

@boulter, thanks for the respond, but that’s not really what I was trying to achieve here. What you are describing is for one row to belong to multiple categories, which is not the case here. I want to be able to provide a URL of combined results, for example, a list of both Education and Psychology degrees. Hopefully this makes sense and is possible!


#4

If Education and Psychology are both values in a Multiselect, the contains filter would do what you want. If they are a regular text field then you can’t yet do ORs in queries. You could run multiple queries though.


#5

@vLumbley, You can use macro and go through all the results and print all the rows that contains one or both or more parameters (pasted as macro parameter). You can fill the query array into the macro parameter and than split the string inside the macro and then passing throught the forcycle with some boolean preset… Than the right values can be printed :wink:
I haven’t found any other way there. Hope this help you.


#6

@TomEjc I got dizzy just from reading that, haha! But I think I got the concept of what you are trying to explain.