I am extending an internal web application project written with HTML, PHP and pure javascript. I want to POST a javascript integer array, alongside with other inputs, into another PHP file for further processing.
A very simplified version of what I would like to achieve is like this:
form.php
<form action="post.php" method="POST">
<!-- along with other inputs -->
<input type="hidden" id="ints" name="ints">
<input type="submit" name="submit" id="submit" value="SUBMIT">
</form>
<script>
var ints = [2,4,6];
document.getElementsByName("ints").value=ints;
</script>
post.php
if (isset($_POST['ints'])){
var_dump($_POST['ints']); //expected an array of numbers or strings
}else{
echo "not POSTed";
}
But it seems that I failed to POST it. I have tried making the input field ints as ints[] and tried using getElementById. The best I have got is a string "2,4,6", and I may have done this using explode() in PHP, but I would like to know if there are better options.
I want to stick with pure javascript, but if it is not possible, I may try other stuffs like jQuery. Any hints and suggestions are appreciated.
,comma separated