0

I have got a filter in tab. I use motors theme. Filter has to redirect on main filter's page with applied options. It redirects and options are applied in list but link is not changed (it should be like this: site.com/?page_id=16410&make=citroen&ca-year=2012&min_price=2000&max_price=200000 ) but it's just like this: site.com/?page_id=16410 (main filter page). On this image I chose Chevrolet cars but it didn't apply: Chevrolet

If I choose one more option, it will apply all of them but I want it to work from tabs properly.

Form code:

<form action="<?php echo esc_url( stm_get_listing_archive_link() ); ?>" method="post">
    <?php foreach ( $tax_query_args as $taxonomy_term_key => $taxonomy_term ): ?>
        <?php //empty($taxonomy_term[0]->numeric) and ?>
        <?php if ( !empty( $taxonomy_term[0] ) ): ?>
            <div class="col-md-<?php echo esc_attr( $filter_columns_number ); ?> col-sm-6">
                <div class="form-group">
                    <select name="<?php echo ( esc_attr( $taxonomy_term_key ) == "price" ) ? "max_price" : esc_attr( $taxonomy_term_key ) ?>" class="form-control">
                        <option value=""><?php printf( esc_html__( 'Select %s', 'motors' ), stm_get_name_by_slug( $taxonomy_term_key ) ); ?></option>
                        <?php foreach ( $taxonomy_term as $attr_key => $attr ): ?>
                            <option value="<?php echo esc_attr( $attr->slug ); ?>"
                                 <?php if ( $attr->count == 0 && !$taxonomy_term[0]->numeric ) {
                                    echo 'disabled="disabled"';
                                } ?>
                                    data-disabled="<?php echo ( esc_attr( $attr->count ) == 0 && !$taxonomy_term[0]->numeric ) ? 'disabled' : "null" ?>">
                                <?php echo ( esc_attr( $taxonomy_term_key ) == "price" ) ? stm_listing_price_view( $attr->name ) : esc_attr( $attr->name ); ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div>
        <?php endif; ?>
    <?php endforeach; ?>
    <div class="col-md-3 col-sm-6">
        <div class="row">
            <div class="col-md-8 col-sm-12">
                <button type="submit" class="button icon-button">
                   <i class="stm-icon-search"></i><?php esc_html_e( 'Search', 'motors' ); ?>
               </button>
            </div>
            <div class="col-md-4 hidden-sm hidden-xs">
                <a href="" class="reset-all reset-styled"
                   title="<?php esc_html_e( 'Reset search fields', 'motors' ); ?>">
                    <i class="stm-icon-reset"></i>
                </a>
            </div>
        </div>
    </div>
</form>
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
  • Were you on the page `/?page_id=16410` already, when you submit this? Sounds like the form might not actually submit, but there is JavaScript code that prevents the normal submit, and loads the filtered data in the background. – CBroe Mar 19 '21 at 12:58
  • No, Tab with form is on default page (site.com) and /?page_id=16410 is catalog with filters (that page is on screenshot) – Sasha Sasha Mar 19 '21 at 13:00
  • If submitting the form just takes you to `/?page_id=16410`, then I don’t see how the filters could actually get applied on the target page, when none of the field values where actually send there to begin with. Can you please check, using your browser dev tools, network panel, what request this actually triggers, when you submit the form? – CBroe Mar 19 '21 at 13:05
  • It has method="post" to send options of filter to /?page_id=16410. It sends them but doesn't apply them – Sasha Sasha Mar 19 '21 at 13:10
  • What are you talking about, your code above contains `method="get"` …? – CBroe Mar 19 '21 at 13:21
  • Sorry, I copied another form. I've edited it – Sasha Sasha Mar 19 '21 at 13:26
  • Well if you want the parameters to show up in the URL, then the method _should_ be GET, not POST. – CBroe Mar 19 '21 at 13:43
  • But if method is GET, submit button just reloals the main page and URL looks like this: site.com/?make=bmw&serie=x3&ca-year=2010 . It's not even redirecting on site.com/?page_id=16410 – Sasha Sasha Mar 19 '21 at 13:51
  • That is due to what is explained under https://stackoverflow.com/q/1116019/1427878 You would need to put the page id into a hidden form field here then. – CBroe Mar 19 '21 at 13:55
  • I this right: ? And should it come after form? – Sasha Sasha Mar 19 '21 at 14:09
  • No, ``, and it needs to be part of the form, not after it. – CBroe Mar 19 '21 at 14:09
  • Thanks a lot, mate. Can you copy your answer so I can select it as solution? – Sasha Sasha Mar 19 '21 at 14:37

1 Answers1

0

If you want the parameters to show in the URL, then you need to use method GET, not POST.

And because your form action URL already contains GET parameters, what is explained under submitting a GET form with query string params and hidden params disappear also needs to be taken into account - those would get discarded, when the form is submitted, so the parameter needs to be supplied via a hidden field instead:

<input type="hidden" name="page_id" value="16410">
CBroe
  • 91,630
  • 14
  • 92
  • 150