Building a simple search by multiple categories Is it possible to build the following/is it the right way in Craft. Been through the docs and searched but stuck.

I just need to build a form on one page with a dropdown select for 2 categories;


Location
Type


That then takes the user to the results page and returns entries where the location and type match.

Can someone be so kind as to provide a sample to get me going please?
Building the form is pretty straightforward, you get the categories from your "locations" and "types" category groups using craft.categories
and loop them to build your select options. I choose to pass the category's slug as the value to submit and /results as the URL to submit to. 

&lt;form action="{{ url('results') }}" method="get"&gt;

    &lt;label&gt;Location&lt;/label&gt;
    &lt;select name="location"&gt;
        &lt;option value=""&gt;all locations&lt;/option&gt;
        {% set categories = craft.categories.group('locations') %}
        {% for category in categories %}
            &lt;option value="{{ category.slug }}"&gt;{{ category.title }}&lt;/option&gt;
        {% endfor %}
    &lt;/select&gt;

    &lt;label&gt;Type&lt;/label&gt;
    &lt;select name="type"&gt;
        &lt;option value=""&gt;all types&lt;/option&gt;
        {% set categories = craft.categories.group('types') %}
        {% for category in categories %}
            &lt;option value="{{ category.slug }}"&gt;{{ category.title }}&lt;/option&gt;
        {% endfor %}
    &lt;/select&gt;

    &lt;button type="submit"&gt;Search&lt;/button&gt;

&lt;/form&gt;


Getting the entries that are related to categories from both, one or non of your category groups is a little bit more tricky.
In case a category in both select options is selected, you need to use the following syntax for your relatedTo parameter
(see Craft docs: "The relatedTo Param - Passing Multiple Relation Criteria"):

{% set cocktails = craft.entries.section('cocktails').relatedTo('and',
    { sourceElement: currentUser, field: 'favoriteCocktails' },
    { targetElement: gin, field: 'ingredients' }
) %}


I suggest to compose the value for the relatedTo parameter starting with an array ['and'] and then build upon this array,
conditionally adding array elements (relation conditions) using the merge filter.

{# Get the search data #}
{% set locationParam = craft.request.getParam('location') %}
{% set typeParam = craft.request.getParam('type') %}

{# Compose the relation param #}
{% set relationParam = ['and'] %}

{% if locationParam %}
    {% set location = craft.categories.group('locations').slug(locationParam).first() %}
    {% set relationParam = relationParam|merge([{ targetElement: location }]) %}
{% endif %}

{% if typeParam %}
    {% set type = craft.categories.group('types').slug(typeParam).first() %}
    {% set relationParam = relationParam|merge([{ targetElement: type }]) %}
{% endif %}

{# Avoid passing an array with `['and']` only #}
{% if relationParam|length &lt; 2 %}
    {% set relationParam = '' %}
{% endif %}

{# Find and list matching entries #}
{% set entries = craft.entries.relatedTo(relationParam) %}

{% if entries|length %}
    &lt;ul&gt;
        {% for entry in entries %}
            &lt;li&gt;{{ entry.title }}&lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% else %}
    No entries found.
{% endif %}