CMS Development

kove
Participant | Partenaire solutions Platinum
Participant | Partenaire solutions Platinum

Search in 2 columns in HubDB with 1 input field

Hey

 

I have ONE inputfield (name). In my HubDB i have ONE Column FIRSTNAME and ONE Column LASTNAME. What i want to achieve is the following:

 

If i type the firstname or the lastname from the person in the input field, the person should be found (no matter if i type in firstname OR lastname).

 

What my code looks right now:

 

{% if request.query_dict.name %}  {% set queryparam = queryparam ~ &vorname__icontains="~request.query_dict.name|urlencode %}

 

Now i can just search for firstname.

 

What i tried is the following:

{% if request.query_dict.name %}
{% set queryparam = queryparam ~ ("&vorname__icontains="~request.query_dict.name|urlencode)  or

("&nachname__icontains="~request.query_dict.name|urlencode)

%}

 

and that one

 

{% if request.query_dict.name %}

{% set queryparam = queryparam ~ ("&vorname__icontains="~request.query_dict.name|urlencode) ~ ("||nachname__icontains="~request.query_dict.name|urlencode)

 

Unfortunately, both examples dont work.

1 Réponse
lscanlan
Ancien salarié HubSpot
Ancien salarié HubSpot

Search in 2 columns in HubDB with 1 input field

Hi @kove,

 

I think this is possible, but it will require some fairly custom logic on your end. HubDB doesn't support OR logic in filtering, which is what you're trying to do here. You're basically trying to grab words from an input and match them against either a first name field OR a last name field.

 

But without using a filter on the table, we can still create some custom logic for this.

 

{% set names = request.query_dict.name|split(" ") %}
{% set table = hubdb_table_rows(XXXX) %}
{% for row in table %}
  {% for name in names %}
    {# print out table cells that you need when names match table cell values #}
  {% endfor %} {# end for name in names #}
{% endfor %} {# end for row in table #}

 

It's not exactly the same thing because you're actually pulling the entire table. But I think this would enable you to accomplish what you're going for. Let me know if that makes sense or if you have any questions about setting it up.

 

 - Leland

Leland Scanlan

HubSpot Developer Support