Hist : siberia problems when GET array manipulated with FORM button
The image archive search page includes a button on the form to toggle between the simple search (on index.php) and the advanced search (on search.php - a very similar page to index.php). The problem is that when the user toggled from basic to advanced, the interface always went to English rather than maintaining the current setting (French, English, Russian).
The problem was that the php to create the URL in the onclick event of that button did not check for the state of items in the GET array other than q, so the lang key-value pair was lost, resulting in the page reverting to the default language (English).
Here's a simplified version of the original php. The problematic bit are the lines creating toggleSearchURL:
$toggleSearchMode = '<div id="toggles">';
$toggleSearchMode .= '<button onclick="window.location=\'';
$toggleSearchURL = 'search.php';
if (isset ($_GET['q'])) {$toggleSearchURL .= '?q='. $_GET['q'];}
$toggleSearchMode .= $toggleSearchURL;
$toggleSearchMode .= '\'"><span class="english">Advanced search</span><span class="french">Recherche avancée</span><span class="russian">Расширенный поиск</span>';
$toggleSearchMode .= '</button>';
$toggleSearchMode .= '</div><!--toggles-->';
echo $toggleSearchMode;
and here's the modified php which preserves both lang and q key-value pairs:
$toggleSearchMode = '<div id="toggles">';
$toggleSearchMode .= '<button onclick="window.location=\'';
$toggleSearchURL = 'search.php';
if (count($_GET) > 0 ) {$toggleSearchURL .= "?";}
$conjunction = "";
if (isset ($_GET['q'])) {
$toggleSearchURL .= 'q='. $_GET['q'];
$conjunction = "&";
}
if (isset ($_GET['lang'])) {
$toggleSearchURL .= $conjunction . 'lang='. $_GET['lang'];
$conjunction = "&";
}
$toggleSearchMode .= $toggleSearchURL;
$toggleSearchMode .= '\'"><span class="english">Advanced search</span><span class="french">Recherche avancée</span><span class="russian">Расширенный поиск</span>';
$toggleSearchMode .= '</button>';
$toggleSearchMode .= '</div><!--toggles-->';
echo $toggleSearchMode;
With not much work, this could be turned into a little function which goes through the entire get array.