UnWorld
UnWorld

Reputation: 139

How can I change the value of a $_GET variable without using a link?

The website I am working with is a property sales site where the user can freely advertise their property. Properties can be for sale or for rental: http://ev-villa.com

The search panel I designed has 2 tabs: For Sale and To Rent. To get a clearer understanding of the following problem I would advise you to load the site from the above URL. As the site is multi-lingual you may have to change the language to English by clicking on the flag icon in the top right of the page.

So the tabs in the search panel (left side of the page) can be clicked by the user and this tab will now change colour to show that it has been selected. This is handled by a variable in the URL called saleType. So if the value of this variable is equal to "torent" then the "To Rent" tab will change colour (The css on the page changes when the variable's value changes). Apart from changing colour this variable also affects the search results gained when the user clicks the search button.

The issue here is that the variable change is done by a link which requires reloading/redirecting. So if these tabs are clicked a few times, the result is that the user will have to click the browser's back button quite a few times to leave the website or to get to other parts of the website.

I am basically looking for an alternative solution to changing the value of this variable in php without using a link so that the value is set without redirecting the browser to a new page. I am trying to avoid the use of JavaScript and other languages, to ensure maximum cross-browser and cross platform compatibility, making sure this website works for browsers that don't support JavaScript or don;t have JavaScript enabled at the time of use.

Upvotes: 0

Views: 98

Answers (1)

Telmo Marques
Telmo Marques

Reputation: 5104

I wasn't happy with my previous answer, so I gave it a little bit more thought. Here's a workaround, completely without JavaScript and without requesting the server:

  1. Instead of 1 form for both types of search (rent/sale), create two identical forms but with different action attributes.

    <!-- Rental -->
    <form action="search.php?saleType=torent" method="get">
    ...
    <!-- Sale -->
    <form action="search.ph?saleType=forsale" method="get">
    ...
    
  2. Use CSS to position the forms on top of one another, and to hide one of the forms.

  3. Use the Checkbox Hack to detect a click event on the form "For Sale" and "To Rent" links (you'll need to make them a <label>), and to hide/show the respective form.

Upvotes: 1

Related Questions