I am trying to implement cascading dropdown menus within a catalyst web app. The objective is to select a database table in the first menu and have the columns in that table appear in the second menu. My strategy is to use Jquery with a PHP helper script to run the query against the database.
Jquery code:
$("#db_table").change(function() {
console.log("dbtable changed");
$("#db_field").load("[% c.uri_for('/field_get.php')%]?choice=" + $("#db_table").val());
});
PHP:
<?php
$username = "webuser";
$password = "webuser";
$hostname = "localhost";
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$selected = mysql_select_db("mousesom", $dbhandle) or die("Could not load database");
$choice = mysql_real_escape_string($_GET['choice']);
$query = "SELECT column_name FROM information_schema.columns WHERE table_name = '$choice';";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo "<option>" . $row{'dd_val'} . "</option>";
}
?>
HTML:
Table:<select id="db_table">
<option selected value="base">Choose a Table</option>
<option value="neurons">Neurons</option>
<option value="peaks_factors">Transcription Factors</option>
<option value="peaks">Peaks</option>
<option value="peaks_selection">Selection</option>
<option value="peaks_histmods">Histone Modification</option>
</select>
Field:<select id="db_field">
<option value="Placeholder">Please Select a Table</option>
</select>
I have thus far verified that the javascript request is firing, but I am not getting the expected response. Based on the log output from the Catalyst test server, it seems most likely the needed arguments are not being passed to the PHP helper script, instead being split off into query params by Catalyst instead...
[info] *** Request 8 (0.013/s) [17122] [Fri Jun 26 19:22:50 2015] ***
[debug] Path is "/"
[debug] Arguments are "field_get.php"
[debug] "GET" request for "field_get.php" from "10.21.136.40"
[debug] Query Parameters are:
.-------------------------------------+--------------------------------------.
| Parameter | Value |
+-------------------------------------+--------------------------------------+
| choice | peaks_histmods |
'-------------------------------------+--------------------------------------'
Clearly this is not what I want to happen and am wondering if Catalyst has another way of passing these params to the helper script or some other workaround. I've been searching various documentations and have, thus far, come up empty-handed. Any help would be appreciated!