In the following use case I'm trying to accomplish only step 3 is not working so far, and I'm working in a Joomla 3.4 environment as I'm working on a module here.
- I have an html form asking for some input and a file upload.
- I process this file with JavaScript to pgp to encrypt it (with this: https://keybase.io/kbpgp)
- Now I want to replace the original file in the form with the encrypted one, or at least add the encrypted one to the form data. This doesn't work so far, how can I accomplish that?
- When everything is done in the JavaScript part
form.submit();is called - An email with the forms plain text encrypted as body text is sent and the file should be added as encrypted attachment.
Some details:
Sending the file unencrypted works quite well, so I thought I can just add the encrypted one, but apparently it doesn't work. The form submits the original content and nothing about the added file. I already searched for some solutions and this code snippet was the result of my research:
var data = new FormData();
data.append('upload_file' , result_buffer);
var xhr = new XMLHttpRequest();
xhr.open( 'POST', '', true );
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
xhr.send(data);
var form = document.getElementById('formencryptmessage');
form.submit();
upload_file is the form input of the original unencrypted file; the $_POST request keeps the original file no matter what I do; result_buffer is a binary buffer with files content; lastly, formencryptmessage is the form id and name.
Edit
The git repo with the code is here: https://github.com/JamborJan/joomlaencryptedcontact
We are talking about this: https://github.com/JamborJan/joomlaencryptedcontact/blob/master/tmpl/default.php
My main intent is to use only the browser session / RAM / hidden input field to do the file encryption and sending. I didn't find a suitable solution so far.
$_POST?