I have a form with a hidden object:

<input id="tracker" type="hidden" name="tracker" value="0"  />

The value is read with JavaScript and increased each time an element is added:

var tracker = document.getElementById("tracker");
var tracked = parseFloat(tracker.value) + 1;
tracker.value = tracked;

This works fine while in HTML and JavaScript, but when I submit the form to PHP the number gets all screwed up:

<form id="uploadForm" action="uploadHandler.php" enctype="multipart/form-data" method="post">
<input id="tracker" type="hidden" name="tracker" value="4"  />
$count = $_POST['tracker'];
echo $count;
// 401234

So lets say if the value in the form is 4, then when its echoed from PHP its value is 401234.
Why is it doing this?

7 Years
Discussion Span
Last Post by thebigpicture

Just html with a starting value of 0.

<form action="uploadHandler.php" enctype="multipart/form-data" method="post" id="uploadForm">
<input type="hidden" name="tracker" value="0" id="tracker" />
<div id="elementContainer"></div>
<input type="button" value="Add Another Image" onclick="addElement();" />
<input type="submit" value="Start Upload" name="submit" onclick="uploadProgress();" /> <input type="button" value="Reset" onclick="resetElements();"/>

I've actually worked around this, but I'm still curious why this happens.
I didn't realize that if you name the file input fields like this (name='uploadFile[]') it basically creates an array when passed to php. (In this case I'm adding them with JavaScript)

newdiv.innerHTML = "<input type='file' name='uploadFile[]' />  <input type='button' value='Remove' onclick='removeElement("+divId+");' />"

So basically you can just iterate through the array in php to move the files.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.