ok. have been fighting this for long now. I have following code that feches html from add site:
$articleClassName = 'relative isolate sf-search-ad cursor-pointer overflow-hidden relative transition-all outline-none p-10 hover:bg-aqua-50 focus:bg-aqua-50 sf-search-ad-legendary -m-8';
$merchantID = '3553552';
$finn_link = 'https://www.addsite.tv/car/used/search.html?orgId='.$merchantID.'&sort='.$sortBy;
$finnTagName = 'article';
$finnAttrName = 'class';
$finnAttrValue = $articleClassName;
$finnDom = new DOMDocument;
$finnDom->preserveWhiteSpace = false;
@$finnDom->loadHTMLFile($finn_link);
$finnHtml = getTags( $finnDom, $finnTagName, $finnAttrName, $finnAttrValue );
function getTags( $finnDom, $finnTagName, $finnAttrName, $finnAttrValue ){
$finnHtml = '';
$domxpath = new DOMXPath($finnDom);
$newDom = new DOMDocument;
$newDom->formatOutput = true;
$filtered = $domxpath->query("//$finnTagName" . '[@' . $finnAttrName . "='$finnAttrValue']");
// $filtered = $domxpath->query('//div[@class="className"]');
// '//' when you don't know 'absolute' path
// since above returns DomNodeList Object
// I use following routine to convert it to string(html);
$i = 0;
while( $myItem = $filtered->item($i++) ){
$node = $newDom->importNode( $myItem, true ); // import node
$newDom->appendChild($node); // append node
}
$finnHtml = $newDom->saveHTML();
return $finnHtml;
}
?>
I have this selection dropdown:
<select id="search-sorter">
<option value="MILEAGE_DESC">Km høy-lav</option>
<option value="MILEAGE_ASC">Km lav-høy</option>
<option value="MODEL">Modell</option>
<option value="PRICE_DESC">Pris høy-lav</option>
<option value="PRICE_ASC">Pris lav-høy</option>
<option selected value="PUBLISHED_DESC">Publisert</option>
<option value="YEAR_ASC">År eldst-nyest</option>
<option value="YEAR_DESC">År nyest-eldst</option>
</select>
In short, I need to pass selected option value to variable $sortBy and reload page to update domDocument view with sorted order. as you can see link is formed with variables in URL. So how in ideal work this should work is that selected options values would be passed to variable $sortBy and after page would reload loading in newDOM using already altered link to source that is supplied by $finn_link and this way achieving result of sorting.
I realy need a hint here :D
Originaly there is also other options but I realy need those to work. I would consider also reloading only part of page that inholds actual html that is efected by changes in domDocument instead of reloading whole page but reload of whole page would work fine too.
I used javascript to do the job with this (I am very bad at javascript so just did what I could gather from all the internet):
and there after I used: