Creation of Search with Filters

Asked

Viewed 43 times

0

Hello, in my project I need to filter the results with the following parameters: Minimum Wage and Maximum Salary, Contract Type. But it only works if the user chooses the options, if he chooses to filter only by contract type and leave the Salary blank, the search does not work.

The Free Market site has the search the way I want to do, when filtering the result, the url adds the filters as the user chooses.

In the future I want to add other filters and sort the results.

Home Page:

<form class="filter" action="/search" method="POST">
    <h2>Filtrar Por</h2>

    <div class="salario">
        <h3>Salário</h3>
        <select class="salario_min" name="salario_min">
            <option value="">Mínimo</option>
            <option value="400">400</option>
            <option value="500">500</option>
            <option value="600">600</option>
            <option value="700">700</option>
            <option value="800">800</option>
            <option value="900">900</option>
            <option value="1000">1000</option>
            <option value="1200">1200</option>
            <option value="1400">1400</option>
            <option value="1600">1600</option>
            <option value="1800">1800</option>
            <option value="2000">2000</option>
        </select>

        <select class="salario_max" name="salario_max">
            <option value="">Máximo</option>
            <option value="400">400</option>
            <option value="500">500</option>
            <option value="600">600</option>
            <option value="700">700</option>
            <option value="800">800</option>
            <option value="900">900</option>
            <option value="1000">1000</option>
            <option value="1200">1200</option>
            <option value="1400">1400</option>
            <option value="1600">1600</option>
            <option value="1800">1800</option>
            <option value="2000">2000</option>
        </select>
    </div>

    <div class="tipo">
        <h3>Tipo de Contrato</h3>

        <select class="tipo" name="tipo">
            <option value="">Todos</option>
            <option value="1">Integral</option>
            <option value="2">Temporário</option>
            <option value="3">Estágio</option>
        </select>
    </div>

    <button type="submit" name="filtrar" class="btn">Aplicar Filtros</button>
</form>
  • 1

    To do that you need to use Javascript to change the URL as you choose an option, but that’s just visual, what has to happen in reality is when an option is chosen you have to make a request http post or get with the parameters chosen for the link/api that returns the results according to what was submitted.

  • Where is the PHP code?

  • You’ll have to use AJAX! Search the web and then edit the question.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.