I'm doing a property website and it's almost complete. I have a simple form with some select boxes where you select a county then with AJAX and PHP it loads back all the cities and towns in that county for the next select box then the user submits their search...
It works fine and loads the next PHP which shows all the results {viewresults} but the problem is that the data is all being sent to the next PHP file using POST. this works fine but as you know it means that the users can't just click back or it will say that they either have to RE-POST the data or whatever. I had thought about simply redirecting them to a 3rd file, i.e. the 2nd file gets all the variables together and just sends them to the third file in the URL using GET but I thought that clicking back would just get you back to where you started from. I am guessing but I have seen this behaviour before on other pages on the interwebness.
So before I went ahead and did it I thought I'd ask the pros.
Is there an easier way to do this? (i.e. to use GET to put variables in URL so users can click back etc.)
Here's the main PHP
Code: Select all
<?php
include ("ajaxheader.inc.php");
?>
<form enctype="multipart/form-data" method="POST" action="index.php?locate=viewresults">
<select id="cp_county" name="cp_county" onchange="getCityList(this)" size="1" style="background-color:#CFBFCF;width:74%;">
<option selected value="%">All Counties</option>
<?php include("area.inc.php"); ?>
</select>
<br><br>
<select id="cp_town" name="cp_town" size="1" style="background-color:#CFBFCF;width:74%;">
<option value="%">All Towns & Cities</option>
</select>
<br><br>
<select name="minprice" size="1" style="background-color:#CFBFCF;width:74%;">
<?php include ("min_price.inc.php"); ?>
</select>
<br><br>
<select name="maxprice" size="1" style="background-color:#CFBFCF;width:74%;">
<?php include ("max_price.inc.php"); ?>
</select>
<input type="hidden" name="srch_property_type" value="%">
<input type="hidden" name="minbeds" value="1">
<input type="hidden" name="maxbeds" value="99">
<br>
<br>
<input type="submit" value="Search NOW!"><br>
</form>Code: Select all
<?php
ECHO <<<HERE
<script type="text/javascript" src="ajax.js"></script>
<script type="text/javascript">
var ajax = new sack();
function getCityList(sel)
{
var countyCode = sel.options[sel.selectedIndex].value;
document.getElementById('cp_town').options.length = 0; // Empty city select box
if(countyCode.length>0){
ajax.requestFile = 'gettown.php?countyCode='+countyCode; // Specifying which file to get
ajax.onCompletion = createCities; // Specify function that will be executed after file has been found
ajax.runAJAX(); // Execute AJAX function
}
}
function createCities()
{
var obj = document.getElementById('cp_town');
eval(ajax.response); // Executing the response from Ajax as Javascript code
}
</script>
HERE;
?>Code: Select all
<?php
require ("config.php");
if(isset($_GET['countyCode'])){
$countycode=$_GET['countyCode'];
// ----------------------------------
// find out county name
$sqlstart = "SELECT `county` FROM `townsandcounties` WHERE `countycode` = '" . $countycode . "' LIMIT 1";
$resultone = mysql_query($sqlstart) or die(mysql_error());
$rowone = mysql_fetch_array($resultone);
$countya = $rowone['county'];
// ----------------------------------
$sql = "SELECT * FROM `townsandcounties` WHERE `countycode` = '" . $countycode . "'";
$result = mysql_query($sql) or die(mysql_error());
$start = "All areas in ". $countya;
echo "obj.options[obj.options.length] = new Option('" . $start. "','" . 0 . "'); \n";
while($row = mysql_fetch_array($result)){
$j=$j+1;
echo "obj.options[obj.options.length] = new Option('" . $row['town']. "','" . $j . "'); \n";
}
}
?>Anyway any help would be greatly appreciated.