Clear form on reset / Unset or clear $_FILES variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
checkmate3001
Forum Newbie
Posts: 4
Joined: Sun Oct 17, 2010 9:53 pm

Clear form on reset / Unset or clear $_FILES variable

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post 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?
Bind
Forum Contributor
Posts: 102
Joined: Wed Feb 03, 2010 1:22 am

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

Post 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
Post Reply