Hey everybody I want to let you know that I have undertaken the grueling task of getting the heck away from WordPress. I was so sick of the problems and updates I had to do all the time. I am now using my ezbloo system and I am integrating all my old posts into the new system. It sucks, but in the end, I will save bundles of time. I needed to keep things simple and that is why I created ezbloo. I'll have more on this later for you guys after I am done with the total integration of my old posts here. So if you are looking for a post and need it faster, shoot me an email and I will make it a priority. [email protected]

Summernote is a free and open-source WYSIWYG (What You See Is What You Get) editor for web applications. It allows users to create, edit, and format text and HTML content with ease. In this article, we will explore how to use Summernote and get the most out of its features. 


Getting Started with Summernote

To get started, you will need to include Summernote in your web application. You can download Summernote from its official website or include it from a CDN (Content Delivery Network). Here is an example of how to include Summernote from a CDN:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote.min.js"></script>
The above code initializes Summernote on a textarea with an id of "summernote".

Working with Summernote

Summernote provides a wide range of features for editing text and HTML content. Here are some of the most commonly used features:
  1. Formatting text: Summernote provides options for formatting text, such as bold, italic, underline, strikethrough, and font size. You can access these options from the toolbar.
  2. Inserting images and videos: Summernote allows you to insert images and videos into your content. You can upload images and videos from your computer or embed them from a URL.
  3. Creating links: Summernote allows you to create links to other pages or websites. You can also set the target of the link to open in a new window.
  4. Tables: Summernote allows you to create tables in your content. You can specify the number of rows and columns and add or delete rows and columns as needed.
  5. Code view: Summernote provides a code view option that allows you to edit the HTML code directly.
  6. Customization: Summernote can be customized to fit your needs. You can add your own toolbar options, customize the style of the editor, and add plugins to extend its functionality.

Saving Summernote Content

Once you have created and edited your content with Summernote, you will need to save it to your server. Summernote provides an easy way to get the HTML content of the editor using the following code:
var content = $('#summernote').summernote('code');
The above code gets the HTML content of the editor and stores it in the "content" variable. You can then use AJAX to send the content to your server for saving. Summernote is a powerful WYSIWYG editor that can help you create and edit text and HTML content with ease. It provides a wide range of features and customization options, making it suitable for a variety of web applications. By following the steps outlined in this article, you can get started with Summernote and begin creating rich content for your web application.

Here are some additional details about Summernote:

  1. Compatibility: Summernote is compatible with a wide range of web browsers, including Chrome, Firefox, Safari, and Internet Explorer. It also works well with popular web development frameworks such as Bootstrap.
  2. Localization: Summernote supports localization, which means that you can translate the editor interface into different languages. Summernote has been translated into over 40 languages.
  3. Plugins: Summernote provides a plugin architecture that allows you to extend its functionality. There are many plugins available for Summernote, including ones for image manipulation, table editing, and video embedding.
  4. Themes: Summernote provides several built-in themes that you can use to customize the look and feel of the editor. You can also create your own themes or modify the existing ones.
  5. Accessibility: Summernote has been designed with accessibility in mind. It provides support for screen readers and keyboard navigation, making it easier for users with disabilities to use the editor.
  6. Documentation: Summernote provides comprehensive documentation that covers all the features and options of the editor. The documentation includes examples and code snippets that you can use to get started quickly.
Overall, Summernote is a powerful and flexible WYSIWYG editor that can help you create rich and engaging content for your web application. Whether you are a web developer or a content creator, Summernote is a tool that you should consider adding to your toolkit. See the next page to see how to save content from summernote.

How do I save content from summernote?

To save content from Summernote, you can follow these steps:
  1. Initialize Summernote on your HTML page using the appropriate code:
$(document).ready(function() {
  $('#summernote').summernote();
});
  1. Create a button or other user interface element that will trigger the save action.
<button id="save-btn">Save</button>
  1. Add an event listener to the save button that will extract the content from Summernote and save it to your server or client-side storage.
$('#save-btn').click(function() {
  var content = $('#summernote').summernote('code');
  // Save content to server or client-side storage
});
In the above code, $('#summernote').summernote('code') retrieves the HTML content from Summernote, which can then be saved using an appropriate method, such as an AJAX request to your server or storing the content in a client-side storage mechanism like local storage or cookies.

Can you show me how?

Certainly! Here's an example of how to save content from Summernote using AJAX to send the data to a PHP file on the server:
  1. HTML code for the Summernote editor and Save button:
<div id="editor"></div>
<button id="save-btn">Save</button>
  1. JavaScript code to initialize Summernote and save the content using AJAX:
$(document).ready(function() {
  $('#editor').summernote({
    height: 300
  });

  $('#save-btn').click(function() {
    var content = $('#editor').summernote('code');

    // Send data to server using AJAX
    $.ajax({
      url: 'save.php',
      type: 'POST',
      data: {content: content},
      success: function(response) {
        console.log(response);
      }
    });
  });
});
  1. PHP code to handle the AJAX request and save the content to a file: save.php file
$content = $_POST['content'];
$file = 'saved-content.html';

if (file_put_contents($file, $content) !== false) {
  echo 'Content saved successfully.';
} else {
  echo 'Error: Unable to save content.';
}
In the above code, $_POST['content'] retrieves the HTML content from the AJAX request and file_put_contents() saves the content to a file on the server. The success or failure of the operation is then echoed back to the client as a response. Note that this is just an example and you may need to modify the code to fit your specific requirements, such as changing the file name, directory, or storage mechanism used for saving the content. On the next page all you will have to do is copy and paste these codes to see them work! Here is the index.php file.
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Summernote</title>
  <link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote.min.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote.min.js"></script>
</head>
<body>
<h1>Summernote</h1>
<form method="post">
  <div id="editor" name="editordata"></div>
  <button id="save-btn">Save</button>
</form>
<script>
$(document).ready(function() {
  $('#editor').summernote({
    height: 300
  });
  $('#save-btn').click(function() {
    var content = $('#editor').summernote('code');
    // Send data to server using AJAX
    $.ajax({
      url: 'save.php',
      type: 'POST',
      data: {content: content},
      success: function(response) {
        console.log(response);
      }
    });
  });
});
</script>
</body>
</html>
Here is the save.php File
<?php
$content = $_POST['content'];
$file = 'test.html';

if (file_put_contents($file, $content) !== false) {
  echo 'Content saved successfully.';
} else {
  echo 'Error: Unable to save content.';
}
?>