I have a situation where I am creating a HTML form using Bootstrap 3, Ajax result and dataTables. Depending on the result of the Ajax call the form contains a number of rows of data. Each row has a select list drop-down which allows the user to select the order for each record prior to saving.
The code that produces the "select list drop-downs" only showing part of the form is:
<form name="Form12" id="orderSave" enctype="multipart/form-data" role="form" >
<input name="MM_insert" type="hidden" value="Form12">
<input type="hidden" name="GroupID" id="OrderGroupID">
"<td align='center' style='color:#333;font-size:0.8em;'> \
<select name='ViewOrder[]' id='ViewOrder' style='color:#333;font-size:0.8em;'required > \
<option value='0' selected>0</option> \
<option value='1'>1</option> \
<option value='2'>2</option> \
<option value='3'>3</option> \
<option value='4'>4</option> \
<option value='5'>5</option> \
<option value='6'>6</option> \
<option value='7'>7</option> \
<option value='8'>8</option> \
<option value='9'>9</option> \
<option value='10'>10</option> \
</select> \
</td>" +
<button class="btn btn-success btn-xs submit-button" type="submit" >Save</button>
</form>
When the form is submitted non of the options selected in the "name='ViewOrder[]' are passed to the data submit script.
Data submit script:
$("#orderSave").submit(function(event){
var group_id = document.getElementById("OrderGroupID").value;
console.log("GroupID: " , group_id);
event.preventDefault();
var form = $('form')[12];
var formData = new FormData(form);
formData.append("GroupID", group_id);
console.log("Form Data: " , formData);
$.ajax({
url:"update_order.php",
data: formData,
method:"POST",
cache: false,
contentType: false,
processData: false,
}).done(function(response){
$('#view_order_Modal').modal("hide");
});
});
Server side script:
if (!isset($_SESSION)) {
session_start();
}
require_once('../../../../../Connections/conn.php');
print_r($_POST['ViewOrder ']);
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$groupid = trim($_POST['GroupID']);
$OrderArray = array();
$OrderArray = $_POST['ViewOrder'];
$updateSQL = sprintf("UPDATE Signage_timeline SET DisplayOrder=%s WHERE CarouselGroupID ='".$groupid ."'",
GetSQLValueString($_POST['DisplayOrder'] = $Order, "text"));
mysql_select_db($database_vex, $conn);
$Result1 = mysql_query($updateSQL, $conn) or die(mysql_error());
In the console (Chrome) apart from displaying the expected "GroupID" nothing else is displayed. In the script that processes the data I have "print_r ($_POST)", which display only the "GroupID".
Where have I gone wrong?