Create Signature Pad & Save Using jQuery in CodeIgniter 4

Share this Article
Reading Time: 5 minutes

Inside this article we will see a very interesting topic i.e How to create a signature pad & save using jquery in CodeIgniter 4. Signature Pad – HTML5 canvas based smooth signature drawing using variable width spline interpolation.

This tutorial will give you a idea to integrate a signature pad into your application and save signature generated image to server. For signature pad integration we will use jquery plugin and to save signature to server as an image we will use CodeIgniter 4 framwork.

Learn More –

Let’s get started.

Download & Install CodeIgniter 4 Setup

We need to download & install CodeIgniter 4 application setup to system.

To set application we have multiple options to proceed.

Here are the following ways to download and install CodeIgniter 4 –

  • Manual Download
  • Composer Installation
  • Clone Github repository of CodeIgniter 4

Complete introduction of CodeIgniter 4 basics – Click here to go. After going through this article you can easily download & install setup.

Here is the command to install via composer –

$ composer create-project codeigniter4/appstarter codeigniter-4

Assuming you have successfully installed application into your local system.

.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 Images Folder

Go to /public folder available at application root. Create a folder with name images. We will save generated signature images inside it.

Make sure images folder should have sufficient permission to write content into it.

Create Controller

Next, we need to create a controller file.

$ php spark make:controller Signature --suffix

It will create a file SignatureController.php at /app/Controllers folder.

Open SignatureController.php and write this complete code into it.


namespace App\Controllers;

use App\Controllers\BaseController;

class SignatureController extends BaseController
	public function index()
		return view('signature-pad');

	public function store()
		if ($this->request->getMethod() == "post") {

			$file_string = $this->request->getVar('signed');

			$image = explode(";base64,", $file_string);

			$image_type = explode("image/", $image[0]);

			$image_type_png = $image_type[1];

			$image_base64 = base64_decode($image[1]);

			$folderPath = ROOTPATH . 'public/images/';

			$file = $folderPath . uniqid() . '.' . $image_type_png;

			$session = session();

			file_put_contents($file, $image_base64);

			$session->setFlashdata("success", "Signature saved successfully");

			return redirect('signature-pad');

Create Layout File

Go to /app/Views folder and create a file with name signature-pad.php

Open signature-pad.php and write this complete code into it.


    <title>Create Signature Pad Using jQuery in CodeIgniter 4</title>

    <link rel="stylesheet" type="text/css" href="">

    <link rel="stylesheet" href="" />

    <link rel="stylesheet" type="text/css" href="">

        .kbw-signature {
            width: 100%;
            height: 200px;

        #sig canvas {
            width: 100% !important;
            height: auto;

    <div class="container">
        <div class="row">
            <div class="col-md-8 offset-md-3 mt-5">
                <div class="card">
                    <div class="card-header">
                        <h5>Create Signature Pad Using jQuery in CodeIgniter 4</h5>
                    <div class="card-body">

                        <?php if (session()->get("success")) { ?>
                            <div class="alert alert-success">
                                <?= session()->get("success") ?>
                        <?php } ?>

                        <form method="POST" action="<?= base_url('submit-signature') ?>">
                            <div class="col-md-12">
                                <label class="" for="">Draw Signature:</label>
                                <br />
                                <div id="sig"></div>
                                <button id="clear" class="btn btn-danger">Clear Signature</button>
                                <button class="btn btn-success">Save</button>
                                <textarea id="signature" name="signed" style="display: none"></textarea>
    <script src=""></script>

    <script src=""></script>

    <script type="text/javascript" src=""></script>

    <script type="text/javascript">
        var sig = $('#sig').signature({
            syncField: '#signature',
            syncFormat: 'PNG'
        $('#clear').click(function(e) {


Create Route

Open Routes.php from /app/Config folder and add these route into it.


$routes->get('signature-pad', 'SignatureController::index');
$routes->post('submit-signature', 'SignatureController::store');


Application Testing

Start development server:

$ php spark serve

URL: http://localhost:8080/signature-pad

When we hit Save button, it will save the signature image into images folder.

We hope this article helped you to learn Create Signature Pad & Save Using jQuery in CodeIgniter 4 in a very detailed way.

Buy Me a Coffee

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.

Find More on CodeIgniter 4 here

Learn Web Development Courses @ $4 only.
Web Development Courses @ $4