Skip to content

Instantly share code, notes, and snippets.

@soomtong
Last active March 2, 2022 12:14
Show Gist options
  • Select an option

  • Save soomtong/6635053 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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--

gil-- commented Oct 31, 2013

Copy link
Copy Markdown

@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

Sylph commented Nov 17, 2013

Copy link
Copy Markdown

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?

ghost commented Nov 20, 2013

Copy link
Copy Markdown

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
Copy Markdown

@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
Copy Markdown
Author

@Kyzereye

Copy link
Copy Markdown

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
Copy Markdown

My solution looks like this:

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

@sprour

sprour commented Mar 24, 2014

Copy link
Copy Markdown

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

tadil commented Mar 30, 2014

Copy link
Copy Markdown

how can i remove

and
please ?
thanks

@audas

audas commented Sep 24, 2014

Copy link
Copy Markdown

Blue boxes, does not resize - driving me insane.

@freedemou1993

Copy link
Copy Markdown

Estimados, buenas tardes,

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

@cloudwales

Copy link
Copy Markdown

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
Copy Markdown

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

miharbi commented Sep 7, 2015

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

@bencagri

bencagri commented Oct 5, 2015

Copy link
Copy Markdown

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

kudlas commented Nov 13, 2015

Copy link
Copy Markdown

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

ghost commented Sep 23, 2016

Copy link
Copy Markdown

@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

karthigesh commented Jul 7, 2017

Copy link
Copy Markdown

echo html_entity_decode($aboutcontent->aboutcontent);

use your content inside this to display the content

@nanadjei

Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

@teddiey

teddiey commented Jun 15, 2019

Copy link
Copy Markdown

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
Copy Markdown
onChange: function(contents, $editable) {
	editor.html( editor.summernote('code') );
},

@C980

C980 commented Jul 12, 2019

Copy link
Copy Markdown

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