есть два файла в приложении chek2.php и res_chek2.php
Цена вопроса 500 - 1000 рублей! Помогите вчера 12 часов провозился ничего не вышло!
ФАЙЛ chek2.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Чек</title>
<script src="http://code.jquery.com/jquery-1.11.0.js"></script>
<script type="text/javascript">
function addField () {
var telnum = parseInt($('#add_field_area').find('div.add:last').attr('id').slice(3))+1;
$('div#add_field_area').append('<div id="add'+telnum+'" class="add"><label> Поле №'+telnum+'</label> <input type="text" width="120" style="width: 125px;" placeholder="Название продукта" name="val[]" id="val" value=""/> <input type="text" width="120" placeholder="Цена магазина" name="val[]" id="val" value=""/> <input type="text" width="120" placeholder="Надбавка" name="val[]" id="val" value=""/> <input type="text" width="120" placeholder="Доставка" name="val[]" id="val" value=""/> <input type="text" width="120" placeholder="Цена для клиента" name="val[]" id="val" value=""/> <input type="text" width="120" placeholder="Зарплата курьера" name="val[]" id="val" value=""/> <input type="text" width="120" placeholder="Остаток" name="val[]" id="val" value=""/><div class="deletebutton" onclick="deleteField('+telnum+');"></div></div>');
}
function deleteField (id) {
$('div#add'+id).remove();
}
</script>
<style>
body {
background-color:#BED6FF;
font-family:tahoma;
}
input {
height: 20px;
margin: 5px;
width:125px;
}
.addbutton {
text-align: center;
vertical-align:middle;
font-size: 13px;
width: 283px;
border: 1px solid #70A9FD;
-webkit-border-radius: 7px;
-moz-border-radius: 7px;
border-radius: 7px;
cursor: pointer;
margin: 2px 0 0 110px;
color: #326DC5;
padding: 4px;
background-color:#BED6FF;
}
.deletebutton {
width: 20px;
height: 22px;
cursor: pointer;
margin: 5px;
display:inline-block;
background: url(delete.png) repeat;
background-position: center center;
background-repeat: no-repeat;
position:absolute;
top: 1px;
left: 1062px;
}
.add {
position:relative;
}
</style>
</head>
<body>
<form method="POST" id="formx" action="javascript:void(null);" onsubmit="call()"><div id="add_field_area" style="margin-top: 45px;">
<?
$array = '|||';
$values = explode("|",$array);
$n = 0;
foreach ($values as $value) {
$n++;
if ($n == 1) {
?><div id="add1" class="add">
<label>Поле №1</label>
<div style="position: absolute; top:-35px; left:80px;"><label>Заказ # <input type="text" name="val[]" value="<? echo $_POST['chek_klienta']; ?>"></label></div>
<input type="text" width="120" style="width: 125px;" placeholder="Название продукта" name="val[]" id="val" value="<?=$value?>"/>
<input type="text" width="120" style="width: 125px;" placeholder="Цена магазина" name="val[]" id="val" value="<?=$value?>"/>
<input type="text" width="120" style="width: 125px;" placeholder="Надбавка" name="val[]" id="val" value="<?=$value?>"/>
<input type="text" width="120" style="width: 125px;" placeholder="Доставка" name="val[]" id="val" value="<?=$value?>"/>
<input type="text" width="120" style="width: 125px;" placeholder="Цена для клиента" name="val[]" id="val" value="<?=$value?>"/>
<input type="text" width="120" style="width: 125px;" placeholder="Зарплата курьера" name="val[]" id="val" value="<?=$value?>"/>
<input type="text" width="120" style="width: 125px;" placeholder="Остаток" name="val[]" id="val" value="<?=$value?>"/>
</div>
<?
} else {
?>
<div id="add<?=$n?>" class="add">
<label> Поле №<?=$n?></label>
<input type="text" width="120" style="width: 125px;" placeholder="Название продукта" name="val[]" id="val" value="<?=$value?>"/>
<div class="deletebutton" onclick="deleteField(<?=$n?>);"></div>
<input type="text" width="120" style="width: 125px;" placeholder="Цена магазина" name="val[]" id="val" value="<?=$value?>"/>
<div class="deletebutton" onclick="deleteField(<?=$n?>);"></div>
<input type="text" width="120" style="width: 125px;" placeholder="Надбавка" name="val[]" id="val" value="<?=$value?>"/>
<div class="deletebutton" onclick="deleteField(<?=$n?>);"></div>
<input type="text" width="120" style="width: 125px;" placeholder="Доставка" name="val[]" id="val" value="<?=$value?>"/>
<div class="deletebutton" onclick="deleteField(<?=$n?>);"></div>
<input type="text" width="120" style="width: 125px;" placeholder="Цена для клиента" name="val[]" id="val" value="<?=$value?>"/>
<div class="deletebutton" onclick="deleteField(<?=$n?>);"></div>
<input type="text" width="120" style="width: 125px;" placeholder="Зарплата курьера" name="val[]" id="val" value="<?=$value?>"/>
<div class="deletebutton" onclick="deleteField(<?=$n?>);"></div>
<input type="text" width="120" style="width: 125px;" placeholder="Остаток" name="val[]" id="val" value="<?=$value?>"/>
<div class="deletebutton" onclick="deleteField(<?=$n?>);"></div>
</div>
<?
}
}
?>
</div>
<div onclick="addField();" class="addbutton" style="z-index: 3;">Добавить новое поле</div>
<div><button type="submit" style="width: 293px; z-index: -1; cursor:pointer; color: cornflowerblue; height: 27px; border-radius: 7px; background-color: floralwhite; margin-left: 110px; margin-top: 11px;">Сохранить</button></div>
</form>
<div style="background-color: rgba(0, 119, 255, 0.56); width: 135px; height: 26px; position: absolute; top: 15px; left: 311px; color:white; text-decoration: none;"><input type="button" onclick="history.go(-1)" value="в NutPro"></div>
<div id="results" border="1" style="margin-top:25px; margin-left: 5px;"></div>
<div id="results2" border="1" style="margin-top:25px; margin-left: 5px;">Заказ № <? echo $_POST['chek_klienta'];?></div>
<table id="tableresults" style="border:1px; font-family:verdana; background-color:#fff; margin:5px;">
<tr>
<th>Наименование</td>
<th>Цена</td>
<th>Надбавка</td>
<th>Цена для клиента</td>
</tr>
<tr>
<td id="array1"></td>
<td id="array2"></td>
<td id="array3"></td>
<td id="array4">4 ячейка</td>
</tr>
<tr>
<td>1 ячейка</td>
<td>2 ячейка</td>
<td>3 ячейка</td>
<td>4 ячейка</td>
</tr>
</table>
<div id="xlop" style="background-color:red; width:100px; height:20px;">РРРРР</div>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript" language="javascript">
function call() {
var msg = $('#formx').serialize();
$.ajax({
type: 'POST',
url: 'res_chek2.php',
data: msg,
success: function(data) {
//$('#results').html(data);
document.write(data);
},
error: function(xhr, str){
alert('Возникла ошибка: ' + xhr.responseCode);
}
});
}
//}
</script>
</body>
</html>
ФАЙЛ res_chek2.php
<?php
header('Content-type: text/html; charset=utf-8');
foreach ($_POST['val'] as $key=>$value)
//echo "$key = $value <br>";
//$k = 'v';
//$keyCount = count($key);
//for ($i=0; $i<$keyCount; $i++)
//$key = $key + $i + $k;
print_r("$key=$value<br>");
?>