Jess McKenzie Jess McKenzie - 6 months ago 17
jQuery Question

HTML5 ContentEditable

I have a few questions regarding HTML5 ContentEditable and PHP, I would be very happy if you could provide me with examples of what I am trying to do so I can get an idea.


  • I have a website that I would like to edit but only if "Admin"is logged in - I can do the login side of things but I am unsure how to code the HTML5 ContentEditable into it so that it does not load when "Admin" is not logged in.

  • How would I save content that is changed in HTML5 ContentEditable?


Answer

How would I save content that is changed in HTML5 ContentEditable?

Assuming that you have a div that's contentEditable, like:

<div id="content" contentEditable="true">here goes your contenteditable content</div>

After you've finished editing (like when you're clicking the save-button) you have to do something like this (with jQuery):

<script type="text/javascript">
$.post('save.php', {
    content : $('#content').html()
}
</script>

You'd then receive a post request with you save.php script. You can access the posted data using $_POST['content'];