Skip to content

Instantly share code, notes, and snippets.

@soomtong
Last active March 2, 2022 12:14
Show Gist options
  • Save soomtong/6635053 to your computer and use it in GitHub Desktop.
Save soomtong/6635053 to your computer and use it in GitHub Desktop.
(deprecated) summernote example with php
<!-- this version of sample is too old. it's not follow recent version of summernote api -->
<!-- should check new apis and examples! sorry I am. -->
<!DOCTYPE html>
<html lang="en">
<!-- include libries(jQuery, bootstrap, fontawesome) -->
<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.no-icons.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css" rel="stylesheet">
<!-- include summernote css/js-->
<link href="build/summernote.css" / rel="stylesheet">
<script src="build/summernote.min.js"></script>
<body>
<div class="summernote container">
<div class="row">
<div class="span12">
<h2>POST DATA</h2>
<pre>
<?php print_r($_POST); ?>
</pre>
<pre>
<?php echo htmlspecialchars($_POST['content']); ?>
</pre>
</div>
</div>
<div class="row">
<form class="span12" id="postForm" action="/summernote.php" method="POST" enctype="multipart/form-data" onsubmit="return postForm()">
<fieldset>
<legend>Make Post</legend>
<p class="container">
<textarea class="input-block-level" id="summernote" name="content" rows="18">
</textarea>
</p>
</fieldset>
<button type="submit" class="btn btn-primary">Save changes</button>
<button type="button" id="cancel" class="btn">Cancel</button>
</form>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#summernote').summernote({
height: "500px"
});
});
var postForm = function() {
var content = $('textarea[name="content"]').html($('#summernote').code());
}
</script>
</body>
</html>
@daslicht
Copy link

Hello, thank you for the example !
Do I understand that correct that the image is transmitted as base64 inline string ?
How would I upload an image to my server so that I can create a thumbnail and add that to the html content.

Is there already something like this?
Cheers
Marc

@gil--
Copy link

gil-- commented Oct 31, 2013

@daslicht Not sure if you still need a hand but something like this should do the trick:

file_put_contents('filename.jpg', base64_decode($base64string));

@Sylph
Copy link

Sylph commented Nov 17, 2013

Hi, thanks for the example.

I do have one question though, how do you populate the textarea with database data containing images?
img/etc html tags inside the textarea are currently removed?

@Marks182
Copy link

Hi, thanks a lot for the PHP example. Nevertheless, I have got the same question regarding to the html tags. Do you have a solution for this problem?

@shinesoftware
Copy link

@Marks182 No, not yet. I have asked to HackerWins at summernote/summernote#59 (comment)

If I convert all the strings came from the database table using the htmlspecialchars function, summernote show me the code correctly but it is not good because all the text saved in the database Must be, in my case, as HTML code and not HTML entities.

http://jsfiddle.net/mikunos/f6vY7/12/

Seems to me that some summernote function strips the html code when a html content is within a textarea.

Any solution?

@soomtong
Copy link
Author

@Kyzereye
Copy link

this is great, but when i run this code, I get a textarea inside the summernote area. Is there a way to get rid of this so it looks cleaner?

Thanks

@markcanals
Copy link

My solution looks like this:

$('.note-editable').on("blur", function(){
var editor = $(this).closest('.note-editor').siblings('textarea.summernote');
editor.html(editor.code());
});

@sprour
Copy link

sprour commented Mar 24, 2014

Hello,
I have some problem. I'm trying to insert an image, but I get this error: "GET http://localhost/summernote/[object%20FileList] 404 (Not Found) " Any ideas?

thanks

@tadil
Copy link

tadil commented Mar 30, 2014

how can i remove

and
please ?
thanks

@audas
Copy link

audas commented Sep 24, 2014

Blue boxes, does not resize - driving me insane.

@freedemou1993
Copy link

Estimados, buenas tardes,

Por favor como hago para guardar los datos del editor en mi base de datos?

@cloudwales
Copy link

Hi im just wondering if theres a way to stop the html cleanup on save? When i use the code markup it thinks it displays it as if it was processed.
Cheers

@darienmh
Copy link

La mejor respuesta la dio @markcanals, sito textualmente.

$('.note-editable').on("blur", function(){
var editor = $(this).closest('.note-editor').siblings('textarea.summernote');
editor.html(editor.code());
});

@miharbi
Copy link

miharbi commented Sep 7, 2015

  $('.note-editable').on("blur", function(){
       $('textarea[name="content"]').html($('#summernote').code());
  });

@bencagri
Copy link

bencagri commented Oct 5, 2015

Hi there, I'm trying to get content like you do. but I'm getting this error,

Uncaught TypeError: $(...).code is not a function

using jquery 1.11.2.

@kudlas
Copy link

kudlas commented Nov 13, 2015

use
$(...).summernote("code") instead

Copy link

ghost commented Sep 23, 2016

@soomtong

same code we have configure it perfectly working on the google chrome but it's not working on the mozilla firefox
can you please help what a problem ?

@karthigesh
Copy link

karthigesh commented Jul 7, 2017

echo html_entity_decode($aboutcontent->aboutcontent);

use your content inside this to display the content

@nanadjei
Copy link

summernote automatically remove the textarea element and replace it with a new one therefore the existing one with the name attribute which php can work with will be gone.

@SoyDiego
Copy link

Hi, someone can help me? Im using summernote and I have 2 problems.
I have my section "NEWS". When I insert a new, my textarea works perfectly with summernote.
The input of my news (imageNews, title, description, news ) are getted with Jquery Ajax
But when I go to "EDIT NEWS", my textarea is with HTML FORMAT and summernote is not showing up. How can I fix it?
ss
Thanks and sorry for my english

@kazitanvirahsan
Copy link

you should have a checking before you want to print out $post['content'] like

if(isset($post['content']

)) {
... print
}

otherwise you will get an error for the first time loading.

@JohnSalazar
Copy link

@teddiey
Copy link

teddiey commented Jun 15, 2019

For some obvious reason <?php gets commented out.
But how can I bypass this.
I want to allow php tags in summernote

@maksam07
Copy link

onChange: function(contents, $editable) {
	editor.html( editor.summernote('code') );
},

@C980
Copy link

C980 commented Jul 12, 2019

Hi friends, I am not able to get html content value in textarea field when I clicked on edit button. Here I am using summernote editor.

here html code:-

<textarea name="description" id="summernote" cols="30" rows="10" value="{{x.description}}">{{x.description}}</textarea>

here script;-

<script> $('#summernote').summernote({ height: 300 }); </script>

Please help me.

my

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment