• I’m trying to link a form (formidable forms) to allow one of my staff to post documents from the front end. I can get the whole thing to work, except for the file upload feature. Can someone help me figure out what I’m missing and why I can’t get the file upload to upload the document?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor nwjames

    (@nwjames)

    @bwgolf24,
    You have not actually stated the problem that you’re having so it is a little difficult to help.

    I assume that you can upload a file since if you could not, you would be raising a problem against the formidable forms file upload feature – a premium option of that plug-in.

    I have loaded a Page and an Attachment (media item), and by making some SQL adjustments have combined them to make a Document, i.e something that looks and behaves like a Document handled by this plug-in. This may give you a clue as to what you are missing.

    The stages I used were:
    1. Create a Page with ONLY the required title. It needs no content. I published it, but is not necessary here. You can do it later. You will need to know its ID. This can be found by editing the Page. In my case it was 5845 and I gave it a title Document.
    For later use, the act of publishing it created a revision – with ID 5846.
    2. Create a Media item for the required file. In my case, I loaded a file called AHO-fadet-gp.pdf. Similarly you need to find its ID. In my case it was 5847.
    You will see that this file appears in the media grid.

    Now we need to do the transformation. For this, you should not use wp_update since pages have, like documents, revisions, but with SQL directly. I used phpMyAdmin, but you are going to need to do this in your program,

    a) Edit the Page (id-5845) to have post_type = ‘document’ and post_content = 5847
    b) Since I had a revision (id=5846), set post_content = 5847
    c) Edit the attachment (id=5847) to have as its parent the document, i.e. set post_parent=5845.

    If you load documents into your media directory, then that is it. The two items Page and Attachment have been consolidated into a single Document able to be handled by the plug-in.

    If you look at your Media files, you will see that the attachment has disappeared since Document attachments are hidden with the plug-in processing.

    I have taken additional time to respond because I had forgotten that I had changed my configuration to have separate Document and Media file locations and I was getting 404 page errors. Once I had moved the file from the Media location to the Document one, all worked as expected.

    Since I had named the Page, Document, to access the pdf I use a permalink of …/documents/2020/12/document.pdf and not its original file name. This is not the name hiding that would be used with the plug-in – but provides something similar.

    Hope this guides you to resolving your problem.

    Regards,
    Neil James

    . .

    Thread Starter bwgolf24

    (@bwgolf24)

    Thanks for the reply. Let me try rephrasing what the problem is. I have a front end form (call it post document) that I have staff using. I have tried no less than 4 different form plugins premium versions trying to get this to work. Right now, when someone posts a document via the form, the document is created in the document post type, the categories are fill correctly, and the author is correct. But there is no file. So then we have to download the file from the form confirmation email, and go to the document custom post type, and upload the file. I would simply like the form to be able to create the document, but I can’t seem to figure out how WP-Document Revisions creates the document as it doesn’t end up in the media library…

    Plugin Contributor nwjames

    (@nwjames)

    @bwgolf24,
    Thanks for your clarification. The intrinsic nature of a Contact Form is that the server is not the wvwntual target, but an e-mail is. So while they may temporarily store the file somewhere – but will be generally inaccesible – and then be deleted. I believe that Contact Form 7 has just implemented a fix where someone used their file upload capability to upload a malicious file and then execute it. The result is that Form plug-ins are likely to become even more difficult to use for this.

    To answer your question, the document form has an upload button that invokes an async-upload ajax call to load the file directly from the browser. That is, it uses the standard media system to load the file.

    To your last sentence, “but I can’t seem to figure out how WP-Document Revisions creates the document as it doesn’t end up in the media library” – unless you have set the option to store the documents in a different place, they DO end up in the media library. It is just that once there is plug-in code that stops you seeing them.

    I am puzzled why you don’t allow your staff to use the WP Document Revisions Form itself since it does manage what you need. Since WP Document Revisions has its own capabilities, you can lock down access to just Documents.

    They could have a specific role – which requires just 3 permissions – read, edit_documents and upload_files. Possibly a fourth to manage the taxonomies. With these they can load documents directly – although they will be in pending status – so will need to be published – either by giving them publish_documents capability.

    [Note that if you have Woocommerce installed, then there is an additional permission required. If interested, we can explore this further.]

    Regards,
    Neil James

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post Document from Form’ is closed to new replies.