HubDB Filters

Hello,

I am working on a page listing remote notaries, and I need assistance with a filter and search bar.

I am attempting to filter by state (state_commissioned) and to add a search bar that will allow searching by name (hs_name). I’m able to get the state options to show up in the filter, but nothing is happening when the option is selected.

I have attached where I’m at below:

<!-- set the filter by drop down, search bar, and submit button -->
<div>
 <form id="form_id" method="get">
 <div>
 <h4>Filter By State: </h4>
 <select name="type" form="form_id" onChange="this.form.submit()">
 <option value="show-all">Show All</option>
 {% set contact = hubdb_table_column(5312178, "state_filter").options %} {% for choice in contact %} {% set type_list = type_list~choice.id|list %} {% if choice.id == request.query_dict.contact %}
 <option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
 {% else %}
 <option value="{{ choice.id }}">{{ choice.name }}</option>
 {% endif %} {% endfor %}
 </select>
 </div>
 <div>
 <input name="city" type="text" id="search-by" class="autocomplete" placeholder="Search by Name">
 </div>
 <input id="submit-button" type="submit" value="search">
 </form>
 <!-- sets the different query parameters using submitted input for hubdb query -->
{% set queryparam = "" %}
{% if request.query_dict.type in ["1", "2", "3", "4"] and request.query_dict.state_filter == "" %}
 {% set queryparam = queryparam ~ "&type="~request.query_dict.type|urlencode %}
{% endif %}
{% if request.query_dict.type in ["1", "2", "3", "4"] and request.query_dict.state_filter != "" %}
 {% set queryparam = queryparam~"&type="~request.query_dict.type|urlencode~"&state_filter__icontains="~request.query_dict.state_filter|urlencode %}
{% endif %}
{% if request.query_dict.type == "show-all" and request.query_dict.state_filter != "" %}
 {% set queryparam = queryparam~"&hs_name__icontains="~request.query_dict.state_filter|urlencode %}
{% endif %}
</div>

{# Get eNotary Network Members from HubDB #}
{% set queryParam = 'orderBy=random()' %}
{% set table = hubdb_table_rows(5312178, queryParam)%}

{% if table == [] %}
 <p class='align-center'>Sorry, no one found for that Search. Try changing your filter and search again.</p>
{% else %}
 {% for row in table %}
<html>
 <head>
 <script src="https://kit.fontawesome.com/a2aef4b109.js" crossorigin="anonymous"></script>
 </head>
 <body>
 <div class="grid-container">
 <div class="image">
 <img src="{{ row["enotary_photo"].url }}">
 </div>
 <div class="text">
 <h4>{{ row.enotary_name }}</h4>
 <h5>{{ row.enotary_company }} </h5>
 <div><b>Time zone: </b>{{ row.time_zone }}</div>
 <div>
 <b>State: </b>{{ row.state_commissioned }}</div>
 <div><i class="fa fa-envelope" style="font-size:18px;color:#568ea3;vertical-align: text-top;"> </i>{{ row.enotary_email }}  </div>
 <div><i class="fa fa-phone" style="font-size:18px;color:#568ea3;vertical-align: text-top;"> </i>{{ row.enotary_phone}}</div>
 </div>
 <div class="certification">
 <img src="{{ row["signix_certifitied"].url }}">
 </div>
 </div>
 </body>
</html>
{% endfor %}
{% endif %}

@Anton , have any thoughts on this?

Hi @JLamb14,

try changing the code as follows:

{% require_js %}
<script src="https://kit.fontawesome.com/a2aef4b109.js" crossorigin="anonymous"></script>
{% end_require_js %}

<!-- set the filter by drop down, search bar, and submit button -->
<div>
 <form id="form_id" method="get">
 <div>
 <h4>Filter By State: </h4>
 <select name="type" form="form_id" onChange="this.form.submit()">
 <option value="show-all">Show All</option>
 {% set contact = hubdb_table_column(5312178, "state_filter").options %} 
				{% for choice in contact %}
				{% set type_list = type_list~choice.id|list %} 
				{% if choice.id == request.query_dict.contact %}
 <option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
 {% else %}
 <option value="{{ choice.id }}">{{ choice.name }}</option>
 {% endif %} {% endfor %}
 </select>
 </div>
 <div>
 <input name="city" type="text" id="search-by" class="autocomplete" placeholder="Search by Name">
 </div>
 <input id="submit-button" type="submit" value="search">
 </form>
 <!-- sets the different query parameters using submitted input for hubdb query -->

</div>

{% set queryparam = "" %}
{% if request.query_dict.type in ["1", "2", "3", "4"] and request.query_dict.state_filter == "" %}
 {% set queryparam = queryparam ~ "&type="~request.query_dict.type|urlencode %}
{% endif %}
{% if request.query_dict.type in ["1", "2", "3", "4"] and request.query_dict.state_filter != "" %}
 {% set queryparam = queryparam~"&type="~request.query_dict.type|urlencode~"&state_filter__icontains="~request.query_dict.state_filter|urlencode %}
{% endif %}
{% if request.query_dict.type == "show-all" and request.query_dict.state_filter != "" %}
 {% set queryparam = queryparam~"&hs_name__icontains="~request.query_dict.state_filter|urlencode %}
{% endif %}

{# Get eNotary Network Members from HubDB #}
{% set queryParam = queryparam ~ 'orderBy=random()' %}
{% set table = hubdb_table_rows(5312178, queryParam)%}

{% if table == [] %}
 <p class='align-center'>Sorry, no one found for that Search. Try changing your filter and search again.</p>
{% else %}
 {% for row in table %}
 <div class="grid-container">
 <div class="image">
 <img src="{{ row["enotary_photo"].url }}">
 </div>
 <div class="text">
 <h4>{{ row.enotary_name }}</h4>
 <h5>{{ row.enotary_company }} </h5>
 <div><b>Time zone: </b>{{ row.time_zone }}</div>
 <div>
 <b>State: </b>{{ row.state_commissioned }}</div>
 <div><i class="fa fa-envelope" style="font-size:18px;color:#568ea3;vertical-align: text-top;"> </i>{{ row.enotary_email }}  </div>
 <div><i class="fa fa-phone" style="font-size:18px;color:#568ea3;vertical-align: text-top;"> </i>{{ row.enotary_phone}}</div>
 </div>
 <div class="certification">
 <img src="{{ row["signix_certifitied"].url }}">
 </div>
 </div>
{% endfor %}
{% endif %}

best,

Anton