我有一个动态创建的 div 数组,每个 div 里面都有图像,并希望通过表单发布图像。
目前我没有收到任何警报
添加了一个 var_dump($_POST) 并得到了这个结果
array(3) {
["imagename"]=> array(1)
{
[5]=> string(35) "upload_pic/thumbnail_1365064772.jpg"
}
["id"]=> array(1)
{
[5]=> string(1) "5"
}
["box_type"]=> array(1)
{
[5]=> string(5) "image"
}
}
如何将其放入 for 循环中?
任何帮助,将不胜感激。
这是我的代码:
javascript:
function NewImgBox(imge, id)
{
id=id+i;
var new1div = document.createElement('div');
new1div.setAttribute('id', id);
new1div.setAttribute('class', 'dragbox');
new1div.setAttribute('iterate',i);
new1div.style.position = "relative";
new1div.style.top = p;
new1div.style.left = p;
new1div.style.cursor='move';
new1div.innerHTML = "</div><br><input type='image' value='"+i+"' disabled name='image["+i +"]' src='"+imge+"' id='"+i+"'class='image1' style='width:300px; height:300px;'>";
new1div.innerHTML=new1div.innerHTML+"<br><input type='hidden' value='"+imge+"' name='imagename["+i+"]'>";
new1div.innerHTML=new1div.innerHTML+"<br><input type='hidden' value='"+i+"' name='id["+i+"]'><br><input name='box_type["+i+"]' type='hidden' value='image'/>";
document.getElementById("frmMain").appendChild(new1div);
}
html:
<form id="frmMain" name="frmMain" enctype="multipart/form-data" action="dynamic_div6.php" method="post">
<input id="btn2" type="button" value="Add New Image" onClick="popitup('upload_crop.php');"/>
<input type="submit" value="Save Page" >
<div id="content">
<?
if($new_image!='')
{
?><script>NewImgBox('<? echo $new_image; ?>','draggable')</script><?
$new_image='';
}
?>
</div>
</form>
php:
if($_SERVER['REQUEST_METHOD'] == "POST")
{
foreach($_POST['image'] as $j => $value)
{
$imagename=$_POST["imagename"][$j];
$box_type=$_POST['box_type'][$j];
$box_id=$_POST['id'][$j];
?><script>alert("imagename=<? echo $imagename; ?>");</script><?
?><script>alert("box_id=<? echo $box_id; ?>");</script><?
?><script>alert("box_type=<? echo $box_type; ?>");</script><?
}
}