Copy form data to clipboard using clipboardjs - clipboard

Is there any way to send the data from a form to the clipboard using clipboardjs?
I know I can send data from a textarea to the clipboard, but not several...
I've been googling for hours...
Thanks
Karlheinz

Related

Laravel Save Markdown to Database - Don't Understand

I am reluctant to post this, but I am having trouble understanding how markdown actually "saves" to a database.
When I'm creating a migration, I will add columns and specify the type of value (i.e. integer, text, string, etc.) and in the course of operation on the website, users will input different information that is then saved in the DB. No problem there.
I just can't seem to wrap my head around the process for markdown. I've read about saving the HTML or saving the markdown file, rendering at runtime, pros and cons all that.
So, say I use an editor like Tiny MCE which attaches itself to a textarea. When I click "Submit" on the form, how does that operate? How does validation work? Feel free to answer my question directly or offer some resource to help further my understanding. I have an app built on Laravel so I'm guessing I'll need to use a package like https://github.com/GrahamCampbell/Laravel-Markdown along with an editor (i.e. Tiny MCE).
Thanks!
Let's start with a more basic example: StackOverflow. When you are writing/editing a question or answer, you are typing Markdown text into a textarea field. And below that textarea is a preview, which displays the Markdown text converted to HTML.
The way this works (simplified a little) is that StackOverflow uses a JavaScript library to parse the Markdown into HTML. This parsing happens entirely client side (in the browser) and nothing is sent to the server. With each key press in the textarea the preview is updated quickly because there is no back-and-forth with the server.
However, when you submit your question/answer, the HTML in the preview is discarded and the Markdown text from the textarea is forwarded to the StackOverflow server where is is saved to the database. At some point the server also converts the Markdown to HTML so that when another user comes alone and requests to view that question/answer, the document is sent to the user as HTML by the server. I say "at some point" because this is where you have to decide when the conversion happens. You have two options:
If the server converts the HTML when is saves it to the Database, then it will save to two columns, one for the Markdown and one of for the HTML. Later, when a user requests to view the document, the HTML document will be retrieved from the database and returned to the user. However, if a user requests to edit the document, then the Markdown document will be retrieved from the database and returned to the user so that she can edit it.
If the server only stores the Markdown text to the database, then when a user requests to view the document, the Markdown document will be retrieved from the database, converted to HTML and then returned to the user. However, if a user requests to edit the document, then the Markdown document will be retrieved from the database and returned to the user (skipping the conversion step) so that she can edit it.
Note that in either option, the server is doing the conversion to HTML. The only time the conversion happens client-side (in the browser) is for preview. But the "preview" conversion is not used to display the document outside of edit mode or to store the document in the database.
The only difference between something like StackOverflow and TinyMCE is that in TinyMCE the preview is also the editor. Behind the scenes the same process is still happening and when you submit, it is the Markdown which is sent to the server. The HTML used for preview is still discarded.
The primary concern when implementing such a system is that if the Markdown implementation used for preview is dissimilar from the implementation used by the server, the preview may not be very accurate. Therefore, it is generally best to choose two implementations that are very similar or, if available, use the same implementations for both.
It is actually very simple.
Historally, in forums, there used be BBCodes, which are basically pseudo-tags that allow you to format your text in some say. For example [b][/b] used to mean "make this text bold". In Markdown, it happens the exact same thing, but with other characters like *text* or **text**.
This happens so that you only allow your users to use a specific formatting, otherwise if you'd allow to write pure HTML, XSS (cross-site scripting) issues would arise and it's not really a good idea.
You should then save the HTML on the database. You can use, for example, markdown-js which is a Markdown parser that parses Markdown to HTML.
I have seen TinyMCE does not make use of Markdown by default, since it's simple a WYSIWYG editor, however it seems like it also supports a markdown-like formatting.
Laravel-Markdown is a server-side markdown render helper, you can use this on Laravel Blade views. markdown-js is instead client-side, it can be used, for example, to show a preview of what you're writing in real-time.

How to send Base64 encode image servlet?

For my project, I had created a "question.jsp" & in that I had used fileupload control to upload image to Servlet. It works perfectly fine for New Entry but when I retrieve the data for update, I succeeded to show image somehow( I had used JSON & images are sent as Base64 string). Image displayed perfectly as background of DIV but now If I submit this data to Servlet it wont save that image because the image is not a part of Form Data.
Now my question is that, Is it possible to assign Base64 encode image to fileupload control? Or how I can send that Base64 encode images back to servlet? (In current scenario, it goes null because fileupload control is send null)
Please help me to provide proper solution for this.
Thanks in Advance
Anand...

Download pdf or image through ajax

I would like to send a lot of data through ajax request to my server which will generate pdf or jpg format according to that data.
Now i have done all that, my issue is to how output that generated pdf/jpg back to the user trough ajax? I guess i might be able to use json for that, but im not really sure how, and i think there would be a lot issues with pdf.
Also if some one gonna suggest using form with hidden inputs that will not work since i have really big multidimensional array with lot's of data and it would simply take to much effort to make it work.
By the way, i am using jquery, but anything else is acceptable as long as it does the job done without making me to rewrite half of my script.
To display a JPG
AJAX: You can return the data hex encoded (be sure to set the content type appropriately: header('Content-type: image/jpeg')). Then you just inject an <img/> element into the DOM and set it's src attribute to the returned Data URI.
HTML: Also, you could inject the <img/>'s with a normal src URL to some location on your server.
For PDF
It's a little more tricky. Some browsers display PDF's natively (Chrome/Firefox), others rely on optional third-party plugins. You can detect these plugins, but can't control whether the PDF is displayed in a window/frame or is downloaded.
If you choose to display, you can create a new window/tab to display it or display it in an iframe dynamically.

Save all AJAX JSON data to file using Fiddler2

I want to save to a file, all the data returned from multiple AJAX requests. The requests are of the same format. And AJAX is using JSON (which encodes text in UTF-8).
I'm trying out "Fiddler Web Debugger" and I've added a filter to show only the AJAX sessions and in the Inspectors-bottom window I can see the returned text that I'm interested in. To view this text in this bottom window I can either select the 'JSON' button or the 'Text' button and then press the "Response is encoded and may need to be decoded" button.
I then tried Menu > File > Save > Save all sessions. This looks like it might be saving what I need but I cant really tell as most of the text is gobbldy gook (just the headers are intelligible).
Is this the best way to save data returned from multiple requests?
Is there some way to translate the gobbledy gook? (I'm guessing the problem has something to do with the UTF-8 encoding).
Ideally the file would show a list of JSON string - one for each returned text. Though, if not, I can parse it to extract the data I need.
Thanks.
UTF-8 encoding is effectively the same as ASCII for most western languages. It sounds more likely that the server is GZIP-compressing the response content which is why it would be binary gibberish instead of plaintext. You can direct Fiddler to automatically decompress and unchunk all responses using the AutoDecode button on the toolbar.
Fiddler offers many different export formats, depending on what your end goal is. You can save in a "lossless" Session Archive Zip (SAZ) format if you plan to reload the content into Fiddler. Or, you can use the options shown by the File > Export command to export in many other formats. Or, you can write a bit of script (Rules > Customize Rules) to export the content in any way you'd like.

How do I separate inline images and attaches using MAPI?

My program uses MAPI for working with Exchange mailboxes. The problem is if a user fires up Outlook, adds a file as an attachment and also opens Paint, selects a region there, copies it into clipboard and pastes into the message body the resulting message showns two attachments.
More specifically, the program calls IMAPIMessage::GetAttachmentsTable() to retrieve the attachments table and that table contains two objects. Is there a way a program can decide whether the "attachment" is really an attached file or a portion of inline content?
You will need to check whether the HTML body (through the img tag) refers to the attachment, either through img:cid and PT_ATTACH_CONENTS_ID property or though the file name (PR_ATTACH_LONG_FILENAME) or contnet location (PR_ATTACH_COMTENT_LOCATION).
The property you are looking for is PR_RENDERING_POSITION (0x370B0003). A -1 means that the attachment is a "normal" attachment and not in-line. If the value is anything other than -1, then that indicates an in-line attachment and the value is the position in the body that the attachment should be rendered at.
Here is the MSDN page describing it.
EDIT:
Dmitry, I do not agree with your comment. I have HTML email messages with in-line attachments and the PR_RENDERING_POSITION is working as described in the MSDN page I posted.

Resources