Jump to content

Can You Loop Within A Form?


OtagoHarbour

Recommended Posts

I was thinking of using the following code to allow the user to upload files.<form action="file-upload.php" method="post" enctype="multipart/form-data"><script type="text/javascript"> <input name="userfile[]" type="file" /><br />; <input type="submit" value="Send files" /></form>However most files do not support multiple file selection. Apparently needs html5. I have been looking into way that people approach this problem. A popular solution is to have multiple <input name="userfile[]" type="file" /> items. However, in my case, the number of input items is variable and typically ranges from 40-60. Is there a way that I can have a while look that keeps asking for file names until the users clicks on a box to say stop. Like for example some sort of JavaScript while loop with a confirm() statement at the end of each loop?Thanks,Peter.

Link to comment
Share on other sites

40-60. Gulp.Do not even think of using confirm. Users despise using it just once because it is a terrible interruption in work flow. More than once will kill your site dead, let alone 40-60!A better strategy would be to capture the onchange event of the file input and use DOM techniques to create a new file input and add it to the DOM below the last file input. The user may elect not to use it, but at least there will only ever be one unused element. Users are accustomed to that sort of thing in email apps and such.To make it really slick, delete the change handler as soon as its used. That way, if the user edits an input, it won't create a second empty input.Your naming convention is correct, BTW.

Link to comment
Share on other sites

A better strategy would be to capture the onchange event of the file input and use DOM techniques to create a new file input and add it to the DOM below the last file input. The user may elect not to use it, but at least there will only ever be one unused element. Users are accustomed to that sort of thing in email apps and such.
Thanks very much for your help. I went though the html DOM tutorial and had a go at implementing what you suggested. I do not think I did it correctly but I thought I would include the code I used to see if I am anywhere near the right track.<html><head> <title> Whatever </title> <meta http-equiv="Content-Language" content="FI" /> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript">function NextFile(){ document.getElementById("Browser").getParent().appendChild(document.getElementById("Browser"));}</script> </head><body><form action="file-upload.php" method="post" enctype="multipart/form-data"> <input id="Browser" name="userfile[]" type="file" onchange="NextFile()"/><br /> <input type="submit" value="Send files" /></form></body></html>Is that close to what you mean or am I way off?Another thought I had was to just use one file input that the user calls repeatedly and there is a running count of the number of files selected and, better still, a listing of the selected files. Does that sound like a good idea from a presentation perspective?Thanks again,Peter.
Link to comment
Share on other sites

You can't store a list of the files the user wishes to upload in firefox, well yes the file names, but not the path location to that file, I had a similar problem when trying to put a confirmation page together with file uploads, if the user went back to amend any details, the user would have to repeat the upload again. In IE you can store the path of files location, but not FF? it treated as a security risk, and therefore prevented.

Link to comment
Share on other sites

Apart from that^^, you're on the right track. There is no getParent() method, though, and even if there were, appended an element that already exists just moves it; it doesn't duplicate it. The cloneNode method would work, except that it will also clone the file reference. Use document.createElement to make a new file input.

Link to comment
Share on other sites

You can't store a list of the files the user wishes to upload in firefox, well yes the file names, but not the path location to that file, I had a similar problem when trying to put a confirmation page together with file uploads, if the user went back to amend any details, the user would have to repeat the upload again. In IE you can store the path of files location, but not FF? it treated as a security risk, and therefore prevented.
It's beginning to seem like the best way to load multiple files is to get the user to zip the files into one folder. I could then unzip them server side as long as my unzip executable was compatible with the zip format the user employed client side. I would use PHP exec() to call the unzip function from a Windows command line. (Maybe Linux in the future.) I was wondering if I could use pkzip.exe to unzip the zip files with PHP exec().Thanks,Peter.
Link to comment
Share on other sites

Apart from that^^, you're on the right track. There is no getParent() method, though, and even if there were, appended an element that already exists just moves it; it doesn't duplicate it. The cloneNode method would work, except that it will also clone the file reference. Use document.createElement to make a new file input.
Sorry. I missed this message before. I was wondering if there would be any problems with just using ftp.Another possibility is maybe to use Silverlight. Someone told me that it only works on IE but I looked at silverlight.net and on wikipedia and it looks like it works on most other browsers as well. Adobe Flash looks light it does exactly what I would like but I'm not sure I want to spend the money yet. Silverlight is free but maybe not as good.I will try document.createElement.Thanks,Peter.
Link to comment
Share on other sites

There is Free lisence for students for FLASH 8 if you google it you will find the link.

Link to comment
Share on other sites

Thanks for the info. However I am not a student and I plan to use the web site for commercial purposes.
Probably there is a option for frelancer or something else also. I cant remeber exactly i took that as student option so i did not pay attention to other option.I dont think there is any problem to use the product in comercial purpose ,created from the free lisence.though i am not totaly sure about this.Reading there ToS would be better choice if you are going to heading into this.
Link to comment
Share on other sites

Probably there is a option for frelancer or something else also. I cant remeber exactly i took that as student option so i did not pay attention to other option.I dont think there is any problem to use the product in comercial purpose ,created from the free lisence.though i am not totaly sure about this.Reading there ToS would be better choice if you are going to heading into this.
Thank you for your help. I use InAFlash and it works great! Problem solved.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...