Page 1 of 1

Clear form on reset / Unset or clear $_FILES variable

Posted: Sun Oct 17, 2010 10:32 pm
by checkmate3001
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.

Re: Clear form on reset / Unset or clear $_FILES variable

Posted: Sun Oct 17, 2010 11:59 pm
by requinix
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?

Re: Clear form on reset / Unset or clear $_FILES variable

Posted: Mon Oct 18, 2010 4:55 am
by Bind
example:

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>
usage:

Code: Select all

<input type="button" name="clear" value="Clear Form" onclick="clearForm(this.form);">
source: http://www.javascript-coder.com/javascr ... t-form.htm