Multidimensional array problems in $_POST
Posted on
16th Feb 2014 07:03 pm by
admin
I'm having trouble with a three-dimensional $_POST array. It starts as a two-dimensional array on this side:
Code: <html>
<head>
<title>test</title>
<script type="text/javascript">
var Dom = {
get: function(el) {
if (typeof el === 'string') {
return document.getElementById(el);
} else {
return el;
}
},
add: function(el, dest) {
var el = this.get(el);
var dest = this.get(dest);
dest.appendChild(el);
},
remove: function(el) {
// var el = this.get(el);
// el.parentNode.removeChild(el);
}
};
var Event = {
add: function() {
if (window.addEventListener) {
return function(el, type, fn) {
Dom.get(el).addEventListener(type, fn, false);
};
} else if (window.attachEvent) {
return function(el, type, fn) {
var f = function() {
fn.call(Dom.get(el), window.event);
};
Dom.get(el).attachEvent('on' + type, f);
};
}
}()
};
Event.add(window, 'load', function() {
var i = 2;
Event.add('add-element', 'click', function() {
var el = document.createElement('span');
el.innerHTML = '<input type="text" name="theArray['+i+']['name']" value="">';
i++;
Dom.add(el, 'content');
Event.add(el, 'click', function(e) {
Dom.remove(this);
});
});
});
</script>
</head>
<body>
<p id="add-element">Add Elements</p>
<form action="testPost.php" name="test" method="post">
<input type="text" name="theArray[1]['name']" value="foo" />
<input type="text" name="theArray[2]['name']" value="bar" />
<div id="content"></div>
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
(If you're wondering why I only have one element it's because this is for a project where I will need nested lists later.)
Now, onto testPost.php to process the code:
Code: <html>
<head>
<title>asdfdf</title>
</head>
<body>
<ul>
<?php
for ($i=1;$i<=count($_POST["theArray"]);$i++){
echo("<li>".$_POST['theArray'][$i]['name']."</li>");
}
?>
</ul>
</body>
</html>
$_POST itself is an array, so we convert from a two-dimensional to a three-dimensional array. For some reason, only the first letter gets printed; the rest of the string gets truncated.
My only request is that you don't suggest I just use a database or something of the like. This has to be easily portable and I will probably merge this into one document later.
Thank you
Your Answer:
Login to answer
99
49
Other forums
ALV List Display to point to another report on Double Click
Hi,
I want my ALV List Display to point to another report on Double Click on its line ite
php sessions,logouts & the bloomin back button!
Hi All,
I've got a cms that members can log into. When they logout, the session is destroyed,
Remove values in array2 from array1
I have two arrays.
Array 1 is where the array key holds various different numbers. For exampl
Locking mysql tables with php
Hi
BACKGROUND:
I have multiple instances of the same php script running in a WAMP environ
Using Curl_multi for processing multiple URLs
Hi,
I am at a loss as to how to implement this. I would like to be able to automatically assi
uploading video files into mysql in php
hi,
I have the video files which i have to upload into mysql db. along with creating thumbnails f
mySQL and PHP search
Hello,
I am trying to code a project and ran into a brick wall with one of my pages. I am pretty
fopen() security
As i understood the usage of fopen() for it to function correctly the Dir you write to has to be rw
some query on multilingual website
Hi all,
Which is the simplest and easiest method to make a website multilingual,
is it put
Why does my crawler script suddenly end with no error?
Hi.
I have written a web crawler script. It will visit a large number of URL's with cURL.