Jump to content
  • 0

Require Pdf File On File Upload Field


ChrisCarlson

Question

7 answers to this question

Recommended Posts

  • 0

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.

Link to comment
Share on other sites

  • 0

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?

Link to comment
Share on other sites

  • 0

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!

Link to comment
Share on other sites

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.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...