How to reload server side with additional parameters taken from user input
How to reload server side with additional parameters taken from user input
I'm trying to create a date filter based on user input of 2 dates. I'm using server side processing to load my tables.
In my php script I am using $_POST variables containing the user input and appending them to the $whereAll variable in SSP::complex to search the database based on the 2 values.
$startdate = $_POST['startdate'];
$enddate = $_POST['enddate'];
if (!empty($startdate ) && !empty($enddate))
{
$whereAll = "Case_Opened >='".$startdate."' AND Case_Opened <='".$enddate."' "; // where case opened is greater than or equal start date and case opened is less than or equal end date
}
echo json_encode(
SSP::complex ($_POST, $sql_details, $table, $primaryKey, $columns, $whereResult=null, $whereAll)
I am using the ajax.data function to add the values taken from the user input.
$(document).ready(function() {
var table = $('#example').DataTable( {
"serverSide": true,
"ajax": {
"url": "/?inc=litigation/testscript",
"type": "POST",
"data": function ( d ) {
d.startdate = $('#startdate').val();
d.enddate = $('#enddate').val();
}
},
When the 2 values are entered the table is refreshed, all of the data is shown rather than the results of the user input. When I set the value in html of the 2 input fields, the results are shown as expected
Answers
Solved it myself so thought I would let everyone know if someone has the same problem. There was an issue within the form that was reloading the page based on the action url of the form. Once I removed the form and used buttons instead, it worked perfectly.
Used an onlick function to reload the page based on the inputs and another to clear the input and reset the table to show full results