CodeIgniter 4 How To Use Froala WYSIWYG HTML Editor Tutorial

Share this Article
Reading Time: 4 minutes
460 Views

Inside this article we will see the concept i.e CodeIgniter 4 How To Use Froala WYSIWYG HTML Editor Tutorial. Article contains the classified information about use of Froala WYSIWYG HTML Editor.

If you are looking for a solution i.e How to integrate Froala WYSIWYG Editor in CodeIgniter then this article will help you a lot for this. Tutorial is super easy to understand and implement it in your code as well.

Froala Editor is one of the most powerful Javascript rich text editors in every single aspect. It is designed with performance in mind and will withstand the most rigorous tests.

Learn More –

Let’s get started.

CodeIgniter 4 Installation

To create a CodeIgniter 4 setup run this given command into your shell or terminal. Please make sure composer should be installed.

$ composer create-project codeigniter4/appstarter codeigniter-4

Assuming you have successfully installed application into your local system.

Environment (.env) Setup

When we install CodeIgniter 4, we will have env file at root. To use the environment variables means using variables at global scope we need to do env to .env

Either we can do via renaming file as simple as that. Also we can do by terminal command.

Open project in terminal

$ cp env .env

Above command will create a copy of env file to .env file. Now we are ready to use environment variables.

Enable Development Mode

CodeIgniter starts up in production mode by default. You need to make it in development mode to see any error if you are working with application.

Open .env file from root.

# CI_ENVIRONMENT = production

 // Do it to 
 
CI_ENVIRONMENT = development

Now application is in development mode.

Create Controller

Open project into terminal and run this command to create controller file.

$ php spark make:controller EditorController

It will create a file EditorController.php inside /app/Controllers folder.

Open this controller file and write this code into it.

<?php

namespace App\Controllers;

use App\Controllers\BaseController;

class EditorController extends BaseController
{
	public function index()
	{
		return view("editor");
	}

	public function formData()
	{
		if ($this->request->getMethod() == "post") {
			echo "<pre>";
			print_r($this->request->getVar());
		}
	}
}

Create View Template

Next,

We will use Froala plugin files (CSS, JS) to add Froala WYSIWYG HTML Editor into page template.

Create a file editor.php inside /app/Views folder. Open view file and write this code into it.

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>How To Use Froala WYSIWYG HTML Editor in CodeIgniter 4</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/froala-editor/4.0.13/css/froala_editor.pkgd.min.css">
</head>

<body>
    <div class="container">

        <h4>How To Use Froala WYSIWYG HTML Editor in CodeIgniter 4</h4>

        <div class="panel panel-primary">
            <div class="panel-heading">How To Use Froala WYSIWYG HTML Editor in CodeIgniter 4</div>
            <div class="panel-body">
                <form action="<?php echo site_url('submit-form') ?>" method="POST">
                    <div class="mt-3">
                        <label>Title:</label>
                        <input type="text" name="title" class="form-control" placeholder="Title">
                    </div>
                    <br />
                    <div class="mt-3">
                        <label>Description:</label>
                        <textarea id="description" name="description" class="form-control" rows="3" placeholder="description" required></textarea>
                    </div>
                    <br />
                    <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                </form>
            </div>
        </div>
    </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/froala-editor/4.0.13/js/froala_editor.pkgd.min.js"></script>
<script>
    $(document).ready(function() {
        var editor = new FroalaEditor('#description');
    });
</script>

</html>

Add Route

Open Routes.php from /app/Config folder. Add these routes into it.

//...

$routes->get("editor", "EditorController::index");
$routes->post("submit-form", "EditorController::formData");

//...

Application Testing

Open project terminal and start development server via command:

$ php spark serve

URL: http://localhost:8080/editor

When you submit data with this, you will get all data of Froala editor into the name attribute of input element where you bound –

We hope this article helped you to learn CodeIgniter 4 How To Use Froala WYSIWYG HTML Editor Tutorial in a very detailed way.

Buy Me a Coffee

Online Web Tutor invites you to try Skillshare free for 1 month! Learn CakePHP 4, Laravel APIs Development, CodeIgniter 4, Node Js, etc into a depth level. Master the Coding Skills to Become an Expert in Web Development. So, Search your favourite course and enroll now. Click here to join.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Was this post helpful?

Learn Web Development Courses Risk Free @ $5 only.
Web Development Courses @ $5