If a user uploads a file other than a PDF file, we're already throwing an error:
Only PDF files are supported, and they must end in .pdf.
However, we should give the user (or actually the browser) a hint in advance, which file types are accepted, see #3032701: Give browsers a hint which file types are accepted as uploads and #3031371: Add allowed file extensions as 'accept' attribute for file uploads to improve UX issues for Core. While it's not in our hands whether the browser turns that hint into a useful filter, at least Firefox, Chromium and Opera do so, while most mobile browsers simply ignore the 'accept' parameter, unless it's 'image/*'. Implementation will improve over time though, as it's a web standard.
While Core goes by extension and most browsers simply turn IANA (aka MIME) types into extensions, too, rather than actually checking the file content, we should choose 'application/pdf' for a more standards-conform approach.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | d7_fillpdf_accept_pdf_files_only_3039043-6.patch | 802 bytes | pancho |
| #3 | fillpdf_accept_pdf_files_only_3039043-3.patch | 3.87 KB | pancho |
| #2 | fillpdf_accept_pdf_files_only_3039043-2.patch | 1.49 KB | pancho |
| #2 | upload_dialog_after.png | 7.25 KB | pancho |
| #2 | upload_dialog_before.png | 7.05 KB | pancho |
Comments
Comment #2
panchoEnclosed patch adds IANA type 'application/pdf' as accept attribute to our
<input type='file'>.I also slightly reworded 'title' and 'description' in order to better convey that while we're using the PDF file as a template, it's not like the user needs to upload a special "PDF template" (a concept that exists for DOCX vs. DOTX and XLSX vs. XLTX files, e.g. A regular .PDF file will do, it only has to contain fillable form fields.
Also, the titles weren't translatable. (All other instances of non-translatable user-facing text need to be covered in a dedicated followup.)
Here's how it looks like before and after the patch:
New PDF file (before):


New PDF file (after):
Update PDF file (before):


Update PDF file (after):
File dialog (Firefox 65/KDE/Linux, before):


File dialog (Firefox 65/KDE/Linux, after):
Comment #3
panchoAdded tests plus fixing some docblocks. Should still be green.
Comment #5
panchoPatch #2 (not #3) may be ported to 7.x-1.x-dev. An easy task for novices.
Comment #6
panchoFor convenience, here's a manually tested patch against 7.x-1.x.
Comment #7
bramdriesenLooks ok :)
Comment #9
liam morlandThanks!