dropdwon send always last value in filter

Issue

i’m trying to do a filter using Dropdown but it’s always sending the last value to the link option
enter image description here

always sending the last option
enter image description here

the filter controller work fine. i believe the problem is in the dropdown menu in blade it doesn’t send the option the link

this is my blade

<form action="{{ action('App\Http\Controllers\HomePageController@processForm') }}" method="POST" class="woocommerce-ordering product-filter">
    @csrf
    <input type="hidden" value="alpha" name="sortoption"id="alpha"> 
    <input type="hidden" value="desc" name="sortoption" id="desc">
    <input type="hidden" value="asc" name="sortoption" id="asc">
                                
    <span class="orderby-label hide-desktop">Sort by</span>
    <span te class="perpage-label">Sort by</span>
    <select name="orderby" class="orderby filterSelect" aria-label="Shop order" data-class="select-filter-orderby">
        <option for="alpha">Ordre Alphabetique</option>
        <option for="desc">Prix Decroissant</option>
        <option for="asc">Prix Croissant</option>
    </select>
</form>

Solution

Your syntax for <option> is wrong. for is an attribute used in <label> tags. The attribute to set an option’s value is value.

You do not need the hidden inputs either.

<form action="{{ action('App\Http\Controllers\HomePageController@processForm') }}" method="POST" class="woocommerce-ordering product-filter">
    @csrf
    <span class="orderby-label hide-desktop">Sort by</span>
    <span class="perpage-label">Sort by</span>
    <select name="sortoption" class="orderby filterSelect" aria-label="Shop order" data-class="select-filter-orderby">
        <option value="alpha">Ordre Alphabetique</option>
        <option value="desc">Prix Decroissant</option>
        <option value="asc">Prix Croissant</option>
    </select>
</form>

Answered By – IGP

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published