Carlson Posted March 24, 2015 Report Share Posted March 24, 2015 Is there a way to require the file upload field to only take a PDF file type document? Can this be achieved in javascript? Quote Link to comment Share on other sites More sharing options...
0 Jan Posted March 25, 2015 Report Share Posted March 25, 2015 Hello ccarls3, I hope, the following code can help: <SCRIPT LANGUAGE="JavaScript"> document.getElementById("InsertRecordfilename").setAttribute("accept","application/pdf"); </SCRIPT> Please, insert the name of your field instead of filename Please add the Header&Footer element, select the Footer element, click the Source button and enter the code. Quote Link to comment Share on other sites More sharing options...
0 Carlson Posted March 27, 2015 Author Report Share Posted March 27, 2015 Thanks, it works great! Quote Link to comment Share on other sites More sharing options...
0 Carlson Posted December 8, 2015 Author Report Share Posted December 8, 2015 Jan , how would i modify this script to allow all image types file extensions, and exclude all others (zip folder attachments, word docs, excel etc)? Quote Link to comment Share on other sites More sharing options...
0 Jan Posted December 18, 2015 Report Share Posted December 18, 2015 Hi Christopher, You can use "image/*" instead of "application/pdf", for example: <SCRIPT LANGUAGE="JavaScript"> document.getElementById("InsertRecordfilename").setAttribute("accept","image/*"); </SCRIPT> You can find more details about the accept attribute: http://www.w3schools.com/tags/att_input_accept.asp Quote Link to comment Share on other sites More sharing options...
0 Carlson Posted November 25, 2016 Author Report Share Posted November 25, 2016 Jan, I have used this script which displays images or PDF by default, however the user can still change file type in attachment dialog and upload a different file type. Is there a way to display javascript warning if user attaches any file other than jpg or jpeg? Also, is there a way to require jpeg without user changing extension type on attachment dialog? Quote Link to comment Share on other sites More sharing options...
0 Meekeee Posted December 24, 2021 Report Share Posted December 24, 2021 Hi! Just an update, you may check this article to restrict upload of file type: https://howto.caspio.com/tech-tips-and-articles/advanced-customizations/restrict-file-types-that-can-be-uploaded-in-a-datapage/ Quote Link to comment Share on other sites More sharing options...
0 Meekeee Posted January 20, 2022 Report Share Posted January 20, 2022 Hi - Just wanted to share this solution. If you want to restrict file type in multiple fields, just like in this article: https://howto.caspio.com/tech-tips-and-articles/advanced-customizations/restrict-file-types-that-can-be-uploaded-in-a-datapage/ You can use this code: <script type="text/javascript"> var files = Array.from(document.querySelectorAll('#InsertRecordFIELDNAME1, #InsertRecordFIELDNAME2, #InsertRecordFIELDNAME3, #InsertRecordFIELDNAME4, #InsertRecordFIELDNAME5')); var extensions = ['pdf']; files.forEach(function(el) { el.addEventListener('change', function(e) { var ext = this.value.match(/.([^.]+)$/)[1]; if (!extensions.includes(ext)){ alert('Invalid file format. Please upload PDF only.'); this.value = ''; } });}); </script> Hope it helps! Quote Link to comment Share on other sites More sharing options...
Question
Carlson
Is there a way to require the file upload field to only take a PDF file type document? Can this be achieved in javascript?
Link to comment
Share on other sites
7 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.