Hamza Zafeer
Hamza Zafeer

Reputation: 2436

Call to undefined function form_open() in CI 4

I am using CodeIgniter 4 and loading form helper in the following way, but it still says,

Call to undefined function form_open()

In BaseController.php i am autoloading form helper.

protected $helpers = ["form"];

Route:

$routes->get('admin/login', 'admin\LoginController::index');

Controller:

public function index()
{
    
    echo view('admin/login');
}

View:

<?php echo form_open('admin/dologin');?>
    <?= csrf_token() ?>
    <div class="input-group mb-3">
      <input type="email" class="form-control" name="email" placeholder="Email">
      <div class="input-group-append">
        <div class="input-group-text">
          <span class="fas fa-envelope"></span>
        </div>
      </div>
    </div>
    <div class="input-group mb-3">
      <input type="password" class="form-control" name="password" placeholder="Password">
      <div class="input-group-append">
        <div class="input-group-text">
          <span class="fas fa-lock"></span>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-4">
        <button type="submit" class="btn btn-primary btn-block">Sign In</button>
      </div>
      <!-- /.col -->
    </div>
  <?php echo form_close();?>

How can i get rid of from this error?

Call to undefined function form_open()

Upvotes: 2

Views: 1572

Answers (1)

steven7mwesigwa
steven7mwesigwa

Reputation: 6730

Loading this Helper

This helper is loaded using the following code:

<?php

helper('form');

In your app/Controllers/BaseController.php file,


<?php

namespace App\Controllers;

// ...

class BaseController extends Controller
{
    public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
    {
        // Do Not Edit This Line
        parent::initController($request, $response, $logger);

        // Preload any models, libraries, etc, here.
        helper("form");
    }
}

Upvotes: 2

Related Questions