Hello everyone,
It's my first post. I've been teaching myself php via books and the net for a couple months now. I've got a form that allows a user to upload a csv file. It then reloads the page and populates another form with the data from the csv file. I want to be able to clear the 2nd form when the user clicks the reset button, however that just re-populates the form with the data from the csv file.
My thought is to unset or somehow clear the $_FILES variable (right now I test if it exists to populate the form). Does anyone know how to do that or if it is even possible?
Thank you for your time.
Clear form on reset / Unset or clear $_FILES variable
Moderator: General Moderators
-
checkmate3001
- Forum Newbie
- Posts: 4
- Joined: Sun Oct 17, 2010 9:53 pm
Re: Clear form on reset / Unset or clear $_FILES variable
Reset buttons don't clear the form - they reset it. To the original values. Which were specified in the HTML that your PHP code created.
You want to see the second form but without the CSV data? What's the point of uploading the CSV then?
You want to see the second form but without the CSV data? What's the point of uploading the CSV then?
Re: Clear form on reset / Unset or clear $_FILES variable
example:
usage:source: http://www.javascript-coder.com/javascr ... t-form.htm
Code: Select all
function clearForm(oForm)
{
var elements = oForm.elements;
oForm.reset();
for(i=0; i<elements.length; i++)
{
field_type = elements[i].type.toLowerCase();
switch(field_type)
{
case "text":
case "password":
case "textarea":
case "hidden":
elements[i].value = "";
break;
case "radio":
case "checkbox":
if (elements[i].checked)
{
elements[i].checked = false;
}
break;
case "select-one":
case "select-multi":
elements[i].selectedIndex = -1;
break;
default:
break;
}
}
}
</script>
Code: Select all
<input type="button" name="clear" value="Clear Form" onclick="clearForm(this.form);">