Привет, я продолжаю получать ошибку PHP неопределенного индекса по опубликованной переменной под названием $ _POST [‘stuff’], когда я пытаюсь опубликовать свою форму данных через ajax … Пожалуйста, помогите
form.php
<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/main-temp.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>IT Request Form - FM-AD-103-01</title>
<!-- InstanceEndEditable -->
<link rel="icon" type="image/ico" href="'.$web_favicon.'">
<link href="'.$web_css.'" rel="stylesheet" />
<!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>-->
<script src="'.$web_jquery.'" type="text/javascript"></script>
<script src="'.$web_jsres.'" type="text/javascript"></script>
<!-- InstanceBeginEditable name="head" -->
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<!-- InstanceEndEditable -->
<script>
<!-- InstanceBeginEditable name="Script_Me" -->
$(document).ready(function() {
$(function() {
$("#submit").click(function() {
if ($("#employee").val() == 1) {
var type = 1;
} else {
if ($("#type").val() == 1) {
var type = 2;
} else {
var type = 3;
}
}
var items = $("#requestItems").val();
alert(items);
var user = $("#user").val();
var date = $("#requestedDate").val();
var by = $("#requester").val();
var loc = $("#loc").val();
var dept = $("#requestDepartment").val();
var items = $("#items").val();
var just = $("#justify").val();
var capabilities = $("#special").val();
$.ajax({
type: "POST",
url: "post.php",
data: {
type: type,
user: user,
date: date,
by: by,
loc: loc,
dept: dept,
stuff: items,
just: just,
capa: capabilities,
items: items
}
})
.done(function(msg) {
alert(msg);
$("#thank1").show();
});
});
$("#requestedDate").datepicker({
beforeShowDay: nonWorkingDates,
dateFormat: "yy-mm-dd",
minDate: 5
})
function nonWorkingDates(date) {
var day = date.getDay(),
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6;
var closedDates = [
[12, 22, 2014],
[12, 23, 2014],
[12, 24, 2014],
[12, 25, 2014],
[12, 26, 2014],
];
var closedDays = [
[Sunday],
[Saturday]
];
for (var i = 0; i < closedDays.length; i++) {
if (day == closedDays[i][0]) {
return [false];
}
}
for (i = 0; i < closedDates.length; i++) {
if (date.getMonth() == closedDates[i][0] - 1 &&
date.getDate() == closedDates[i][1] &&
date.getFullYear() == closedDates[i][2]) {
return [false];
}
}
return [true];
}
});
$("#employee").change(function() {
var type = $("#employee_type option:selected").text();
if (type == "New Employee") {
$("#requestedUser").text("New Employees Name:");
$("#name").show();
} else {
$("#requestedUser").text("Current Employees Name:");
$("#name").show();
}
});
$("#submit").click(function() {
$("#sending").toggle();
window.scrollTo(0, 0);
$("body").css({
"overflow": "hidden"});
setTimeout("window.close()", 5000);
});
});
<!-- InstanceEndEditable -->
</script>
</head>
'; } ?>
<body style="overflow: scroll">
<div class="container" style="width:800px;">
<!-- InstanceBeginEditable name="main" -->
<form id="req">
<div id="form_header" style="height:120px;">
<div id="logo_main" title="Dyer & Butler Logo">
<h3 style="padding:55px 0 0 7.5px;">IT Equipment/Software Requistion Form</h3>
</div>
<div style="float:right; width:200px; text-align:right; margin: 10px 20px;">
FM-AD-103-01
</div>
</div>
<div style="clear:both"></div>
<fieldset>
<span class="question">Please Choose Employee Type:</span>
<select id="employee" class="options">
<option value="" disabled selected>- - - - - - - Select your option - - - - - - -</option>
<option value="1">New Employee</option>
<option value="2">Current Employee</option>
</select>
</fieldset>
<fieldset style="display:none;" id="name">
<span class="question" id="requestedUser"></span>
<input type="text" id="user" />
</fieldset>
<fieldset>
<span class="question">Request Type:</span>
<select class="options" id="type">
<option value="" disabled selected>- - - - - - - Select your option - - - - - - -</option>
<option value="1">Acquisition</option>
<option value="2">Replacement</option>
</select>
</fieldset>
<fieldset id="request_items">
<span class="question">Requested Items</span>
<div style="clear:both"></div>
<select style="float:right;" multiple="multiple" id="requestItems" name="my-select[]">
<optgroup label="Hardware">
<option value="mobile">Mobile Phone</option>
<option value="desktop">Desktop</option>
<option value="laptop">Laptop</option>
</optgroup>
<optgroup label="Operating System">
<option value="XP">Windows XP</option>
<option value="Windows 7">Windows 7</option>
</optgroup>
<optgroup label="Software">
<option>MS Project</option>
<option>PDF Pro 10</option>
</optgroup>
<optgroup label="Other">
<option value='elem_1'>MiFi</option>
<option>Printer</option>
</optgroup>
</select>
<span style="float: left; width: 250px;margin: 10px; color: #f00; font-size: 10pt;">All equipment is subject to IT rules, don't always expect to get what you request it is subject to Job Title and Business needs</span>
</fieldset>
<fieldset>
<?php $SQL=m ysqli_query($db_data, "SELECT user_forename, user_surname FROM db_users WHERE user_login ='".$_SESSION[ 'db_user_token'][1]. "'"); $data=m ysqli_fetch_array($SQL); ?>
<span class="question">Requested By:</span>
<input type="text" id="requester" value="<?php echo $data['user_forename'] . " " . $data['user_surname']; ?>" readonly="readonly" />
</fieldset>
<fieldset>
<span class="question">Date Equipment/Software required by:</span>
<input type="text" id="requestedDate" placeholder="dd/mm/yyyy" />
</fieldset>
<fieldset>
<span class="question">Location of Employee:</span>
<select id="loc" class="options">
<option value="" disabled selected>- - - - - - - Select your option - - - - - - -</option>
<option>Head Office</option>
<option>Heathrow (main)</option>
<option>Heathrow (Snowbase)</option>
<option>Gatwick</option>
<option>Dyer & Butler Electrical</option>
<option>London</option>
<option>Milton Keynes</option>
<option>Mersham</option>
<option>Exeter</option>
<option>Swindon</option>
<option>Swansea</option>
</select>
</fieldset>
<fieldset>
<span class="question">Department of Employee:</span>
<input type="text" id="requestDepartment" />
</fieldset>
<fieldset>
<span class="question">Will it be Connected to the Network?</span>
<br/>
<div style="float:right; width: 200px;">
<input class="radio_cmd" type="radio" name="networking" />Yes
</div>
<div style="float:right; width: 200px;">
<input class="radio_cmd" type="radio" name="networking" />No
</div>
</fieldset>
<fieldset>
<span class="question">Justification:</span>
<textarea id="justify" placeholder="Please Justify why replacement is required?"></textarea>
</fieldset>
<fieldset>
<span class="question">Special Capabilities:</span>
<textarea id="special" placeholder="Please specify any special capabilities?"></textarea>
</fieldset>
<script src="../../web_theme/Default/javascript/jquery.multi-select.js" type="text/javascript"></script>
<script>
$('#requestItems').multiSelect()
</script>
<input type="button" class="cmd" style="float: right; padding: 10 25;" id="submit" value="submit" />
</form>
Post.php
<?php
session_start();
include( "../../../db_conn/index.pas");
date_default_timezone_set( 'Europe/London');
$items=array(); $items=$_POST['stuff']; //get the values from the keeporder
mysqli_query( $db_data, "INSERT INTO
db_requests (
`req_type`,
`req_user`,
`req_date`,
`req_by`,
`req_location`,
`req_dept`,
`req_items`,
`req_just`,
`req_capabilities`,
`req_day`
)
VALUES (
'".$_POST[ 'type']. "',
'".$_POST[ 'user']. "',
'".$_POST[ 'date']. "',
'".$_POST[ 'by']. "',
'".$_POST[ 'loc']. "',
'".$_POST[ 'dept']. "',
'".$items. "',
'".$_POST[ 'just']. "',
'".$_POST[ 'capa']. "'
, NOW()
)
"); ?>
Это просто данные Multiselect.js, которые я почему-то не могу опубликовать, но тогда документация о том, как их использовать, хороша, но не объясняет, как извлечь из нее значения / данные.
Скрипт с этого адреса: http://loudev.com/
Спасибо всем, кто может мне помочь … 🙂
Задача ещё не решена.
Других решений пока нет …