We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15987
    • 786 Posts
    I have been searching far and wide for a solution to this and cannot seem to find one. If anyone can help it would be greatly appreciated.

    I have a snippet that creates a form. The form has a few input boxes and an input box type file for uploading a file to my server. When the form is submitted it posts back to the same page. I do some error checking to make sure that all required fields are filled in. If there is an error I have ti display the form again so corrections can be made. This is where I am having problems. I can refill all of the input boxes with the previous values except for the one with type file.

    Here is what I have tried so far.

    1. Use the on change event to set a hidden input field with the value of the file input box. Then use the hidden value to replace the value of the file input.

    2. Get the value like above but use javascript to replace the value.

    I can’t seem to find any help on the internet about this. If anyone knows a good way to do this it would be greatly appreciated.

    Kyle
      • 7923
      • 4,213 Posts
      Why need to have the allready uploaded file to be sent as form data again? You could do like this: In the form validation, if some file is allready uploaded and no file is selected to upload, continue without error. If some file is allready uploaded but some file is also selected to upload, upload it by replacing the old one (or what ever you want to do with it). If no file uploaded yet, require some file to be selected for uploading.




        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 15987
        • 786 Posts
        Hmm, never thought of that. I’ll give it a try. Although from an end-user stand point I could see them always clicking to find the file again because the field would be blank.
          • 7923
          • 4,213 Posts
          I have done pretty much same thing in one project while a go.. I did it like this:

          When there was file allready uploaded, the file input was hidden in the form and the name of the uploaded file was outputted as text in the same place. Then there was also a check box with label "Replace file" beside the filename and when it was clicked, an onClick javascript showed (or hide on uncheck) the file input area from what users could choose a new file what would be used to replace the allready uploaded file..



            "He can have a lollipop any time he wants to. That's what it means to be a programmer."
            • 15987
            • 786 Posts
            That sounds like a pretty good solution to me. Thanks for the ideas.