arsnova Posted June 30, 2009 Share Posted June 30, 2009 I've written a form that loads multiple files into an array upon posting. Let's say the form has three inputs: <form name="submission" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="500000" /> <input type="file" name="pr_img_file_array[]" /> <input type="file" name="pr_img_file_array[]" /> <input type="file" name="pr_img_file_array[]" /> <input type="submit" class="submit" name="Submit" value="SUBMIT" /> </form> If a user clicks "browse" next to one of the form inputs, queues a file, then decides, "hey, I don't want to upload a file afterall," what is an appropriate way to prevent the field from validation (to clear the input box from containing a variable)? Does the file handler contain a function like 'unlink' for this purpose, or am I making this more complicated than needed? Thanks, everyone. Link to comment https://forums.phpfreaks.com/topic/164313-solved-clearing-_files-browse-field-before-posting-form/ Share on other sites More sharing options...
arsnova Posted July 2, 2009 Author Share Posted July 2, 2009 Seems that form security prevents this from happening server-side, but javascript handles it nicely. I found the solution here (also read the comments): http://gusiev.com/2009/04/clear-upload-file-input-field/ Thanks to the bloggers for this--in case the link becomes inactive, here's the stripped code I used: <script> function clear_filebrowser(id) { var parent = document.getElementById(id).parentNode parent.innerHTML = parent.innerHTML; } </script> <html> <div><input id="file_initial" type="file" name="pr_img_file_array[]" /></div> <a href="#" onclick="clear_filebrowser('file_initial'); return false;" />CLEAR</a> </html> Link to comment https://forums.phpfreaks.com/topic/164313-solved-clearing-_files-browse-field-before-posting-form/#findComment-868030 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.