So I have a bunch of paragraph elements which are dynamically populated from a db. I have made the elements contenteditable. I now want to submit edits back the the db via a standard form submission. Is there a way to post the contenteditable elements back?
相关问题
- Browser automatically inserts unwanted code on ent
- How to avoid removing typed text from contentedita
- javascript execCommand('delete') not delet
- Reliable cross-browser info on ContentEditable
- window.getSelection() for contenteditable div *on
相关文章
- HTML5 control
- Content-Editable in the angular js
- How to save data in model using Yii2 grid with Edi
- Cross-browser strong/em insertion using execComman
- Chrome doesn't get the selected html string wr
- How reliable is using contenteditable on a div for
- Enable CKEditor4 inline on span and other inline t
- `contenteditable = true` height issue in FireFox
Does it NEED to be standard form submission? If you cannot or do not want use a form with inputs, you may try AJAX (XMLHttpRequest + FormData), through which you could perform asynchronous requests and control better how response shows up.
If you want it even simpler, try jQuery's
$.ajax
function (also$.get
and$.post
). It sends data using simple JS objects.If you use jquery, you could submit the content with a .click() event (i.e "save" or "submit"...)
In your click function post it to a server side script using an ajax "post" to insert it into your database.
Example
You have to use javascript one way or the other, it won't work as a "standard" form element as it would with a textarea or the like. If you like, you could make a hidden textarea within your form, and in the form's onsubmit function copy the innerHTML of the contenteditable to the textarea's value. Alternatively you could use ajax/xmlHttpRqeuest to submit the stuff a bit more manually.
If anyone is interested I patched up a solution with VueJS for a similar problem. In my case I have:
In "data" you can set a default value for mainMessage, and in methods I have:
"d-none" is a Boostrap 4 class for display none. Simple as that, and then you can get the value of the contenteditable field inside "gift[main_message]" during a normal form submit for example, no AJAX required. I'm not interested in formatting, therefore "innerText" works better than "innerHTML" for me.