Skip to content

All topics  /  PHP

How to add Summernote Editor in PHP?

PHP

Teams applying “How to add Summernote Editor in PHP?” in a production project can use stretch assignment to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.

Before copying the example into a live application, confirm version-specific behaviour with the PHP project and test it against the project’s actual database and runtime.

Apr 06, 2022

Hi friends,

In this post, we will learn how to use summernote editor in php. i explained simply how to use summernote editor in php step by step. Here you will learn how to use summernote editor in php form. This tutorial will give you simple example of how to add summernote editor in php code.

I will give you simple Example of how to use summernote editor with php.

So let's see bellow example:

config.php


<?php
    $host = "localhost";
    $user = "root";
    $password = "";
    $dbname = "demos";
    $con = mysqli_connect($host, $user, $password,$dbname);
    if (!$con) {
        die("Connection failed: " . mysqli_connect_error());
    }
?>

index.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>How to add Summernote Editor in PHP? - Nicesnippets.com/</title>
    <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" />
    <!-- include summernote css-->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote-lite.min.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <!-- include summernote js-->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/summernote-lite.min.js"></script>
</head>
<body>
    <?php 
        include "config.php";
        if(isset($_POST['submit'])){
            $title = $_POST['title'];
            $long_desc = $_POST['long_desc'];
            if($title != ''){
                mysqli_query($con, "INSERT INTO contents(title,long_desc) VALUES('".$title."','".$long_desc."') ");
                header('location: index.php');
            }
        }
    ?>
    <div class="container mt-4">
        <div class="row">
            <div class="col-md-12">
                <div class="card">
                    <div class="card-header text-center bg-primary text-white">
                        <h4>How to add Summernote Editor in PHP? - Nicesnippets.com</h4>
                    </div>
                    <div class="card-body">
                        <form method='post' action=''>
                            <div class="mb-3">
                                <label><strong>Title :</strong></label>
                                <input type="text" name="title" class="form-control">
                            </div>
                            <div class="mb-1">
                                <label><strong>Long Description :</strong></label>
                                <textarea id='makeMeSummernote' name='long_desc' class="form-control"></textarea><br>
                            </div>
                            <div class="d-flex justify-content-center">
                                <input type="submit" name="submit" value="Submit" class="btn btn-success">
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Script -->
    <script type="text/javascript">
        $('#makeMeSummernote').summernote({
            height:200,
        });
    </script>
</body>
</html>

Output:

I hope it will help you....