Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Brand3000's avatar

A variable in the url and the except rule which doesn't work

Hello! I have a variable which is set for being included in the Url via the $queryString array. Everything works fine, but! If I load a page with some variable in the Url and then make it in null, it still persists in the url. I want to say that the except rule doesn't work in this scenario. A bit of code:

	public $inStock = null;
    protected $queryString = [
        'inStock' => ['except' => null],
    ];

If I load a page with this variable like so /products?inStock=1 and then uncheck the checkbox for unsetting the inStock variable, it still persists in the url like so `/products?inStock='. I'd like the variable to disappear from the Url. Could somebody give me a clue?

0 likes
3 replies
Amaury's avatar

@brand3000 Hi, it’s a front concern, isn’t it? You can use a javascript function to remove the query string (or the corresponding parameter) when the user uncheck the checkbox…

On unchecked call a function like this (replace 'parameter' withe the name of yours):

const url = new URL(window.location.href);
if(url.searchParams.get('parameter')) {
	url.searchParams.delete('parameter');
    history.replaceState(history.state, '', url.href);
}
Brand3000's avatar

@Amaury As I described, everything works as intended if the URL doesn't have any variable in GET. The problem happens if the URL has a variable upon loading the page. This makes me confused. =(

xshanj2's avatar

Hi, I have the same problem. Did you find a solution?

Please or to participate in this conversation.