Search code examples
javascriptjquerytypo3realurl

Real url not working for url build by javascript TYPO3


I configured the extension tt_address in my page. I need to filter the address by its year. So I build a select box. I need to append some query parameter with its url to access in controller for implementing the filter. The functionality is done successfully. But realurl is not working for this particular functionality.

main.js

function initYearFilter() {
    var selectedItem = sessionStorage.getItem('year');
    if (selectedItem !== null) {
        $('.year-filter select').val(selectedItem);
    }
    $('.year-filter select').on('change', function () {
        var loc = location.href.match(/.*people\/alumni\/+/)[0],
            url;


        if ($(this).val() == 'reset') {
            url = loc + '?no_cache=1';
        } else {
            url = loc + '?ts_address[year]=' + $(this).val() + '&no_cache=1';
        }

        sessionStorage.setItem("year", $(".year-filter select").first().val());

        window.location.href = url;
    });
}

My realurl config

'postVarSets' => array(
            '_DEFAULT' => array(
                'year' => array(
                    array(
                       'GETvar' => 'ts_address[year]',
                    ),
                ),
              ),
              )

Solution

  • Don't let urls being generated manually in frontend, like you do in Javascript.

    My advice here would be to generate the urls backend side and attach it to a option attribute (data-reset-url, data-url).

    // maybe a foreach here
      $GLOBALS['TSFE']->cObj->typolink_URL([
          'parameter' => '_PAGEUID_',
          'additionalParams' => '?ts_address[year]=' . $year, // suppose in foreach have year var
          'no_cache' => true
      ]);