CodeIgniter PHP Fatal error: Call to undefined function form_open()

Bob

I am quite new to PHP and CodeIgniter itself. I know that this error will be encountered when you don't load the form helper. However, I have added in and still face this error.

Please take a look at my codings.

This is my View: Create

<?php echo form_open('studCred/Create'); ?>
                 <?php echo validation_errors(); ?>
                    <div class="row">
                      <div class="col-xs-6 col-sm-6 col-md-6">
                        <div class="form-group">
                          <label>Username</label>   
                          <input type="text" class="form-control" name="username" placeholder="Username">

                        </div>
                      </div>
                      <div class="col-xs-6 col-sm-6 col-md-6">
                        <div class="form-group">
                         <label>Email</label>
                        <input type="email" class="form-control" name="email" placeholder="Email">
                    </div>
                      </div>
                      </div>
                       <div class="row">
                      <div class="col-xs-6 col-sm-6 col-md-6">
                      <div class="form-group">
                    <label>Password</label>
                    <input type="password" class="form-control" name="password" placeholder="Password">
                    </div>
                    </div>

                      <div class="col-xs-6 col-sm-6 col-md-6">
                        <div class="form-group">
                          <label>Admin No</label>
                              <input type="text" class="form-control" name="adminNo" placeholder="AdminNo">

                        </div>
                      </div>
                      <div class="col-xs-6 col-sm-6 col-md-6">
                        <div class="form-group">
                          <label>Phone number</label>
                           <input type="number" class="form-control" name="phone" placeholder="Phone">

                        </div>
                      </div>
                       </div>

                    <input type="submit" value="Submit" name="save" class="btn btn-skin btn-block btn-lg">

                    <p class="lead-footer">* We'll contact you by phone & email later</p>


                  </form>

This is my Controller: studCred

    class studCred extends CI_Controller {

     public function __construct()
{
    parent::__construct();

    $this->load->library('form_validation');    
     $this->load->helper('form');
     this->load->model('studCredModeller');
}
    //Register students
    public function create() {

    //load registration view form
    $this->load->view('studCred/Create')

    ;

    //set validation rules
        $this->form_validation->set_rules('username', 'Username', 'required|callback_check_username_exists');
        $this->form_validation->set_rules('adminNo', 'AdminNo', 'required|callback_check_adminNo_exists');
        $this->form_validation->set_rules('email', 'Email', 'required|callback_check_email_exists');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_rules('phone', 'Phone',  'required');

         if ($this->form_validation->run() === FALSE){
             $this->load->view('studCred/Create');
         }
         else 
         {
             this->studCredModeller->saveRecords();
             this->load->view('nypportal');


        }
    }
}

Model: studCredModeller

if (!defined('BASEPATH'))
    exit ('No direct script access allowed!');

class studCredModeller extends CI_Model
{
    public function saveRecords();
    {
         $this->load->helper('url');

        $data = array(
        'username' =>$this->input->post('username'),
        'admin_no' =>$this->input->post('adminNo'),
        'email' =>$this->input->post('email'),
        'password' => $this->input->post('password'),
        'phone' => $this->input->post('phone'));

        return $this->db->insert('stud_login', $data);

}
}

Thank you. Putting it into the config/autoload.php didn't work either.

Pradeep

Hope this will help you :

You have series of typo error in your code, so remove them one by one and then check again

create method should be Create, add $ to here this->studCredModeller->saveRecords(); and here this->load->view('nypportal');

You are also missing url helper in controller so use url helper in controller instead of using in model

Note : controller name should start with capital letter and must match with file name, and better use url helper and form helper in autoload.php

Your controller __construct() method should be like this :

public function __construct()
{
    parent::__construct();

    $this->load->library('form_validation');    
    $this->load->helper('form');
    $this->load->helper('url');
    this->load->model('studCredModeller');
}

And Remove ; after the method saveRecords(); in your model , should be like this:

public function saveRecords()
{
    $this->load->helper('url');
    $data = array(
      'name' =>$this->input->post('username'),
      'admin_no' =>$this->input->post('adminNo'),
      'email' =>$this->input->post('email'),
      'password' => $this->input->post('password'),
      'phone' => $this->input->post('phone')
    );
    return $this->db->insert('stud_login', $data);
}

for more : https://www.codeigniter.com/user_guide/general/index.html

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

PHP Fatal error: Call to undefined function Laravel tinker

PHP Fatal error: Call to undefined function json_decode()

PHP Fatal error: Call to undefined function imagecreatefrompng()

Wordpress - PHP Fatal error: Call to undefined function get_bloginfo()

Fatal error: Uncaught Error: Call to undefined function ereg_replace() PHP 7

Deployer - Fatal error: Call to undefined function server()

Call to undefined function iconv() fatal error - Suitecrm

In PHP 7.0 Fatal error: Uncaught Error: Call to undefined function json_encode()

PHP Fatal error: Call to undefined function?

Fatal error: Call to undefined function gmp_sign() in php

PHP Fatal error: Call to undefined function json_decode() on Cpanel

Fatal error: Call to undefined function gregoriantojd() in docker PHP

Fatal Error: Call to undefined function imap_open PHP

Fatal error: Call to undefined function normalizamyway() php abstract class

Fatal Error: Call to undefined function curl()

PHP Error: Fatal error: Call to undefined method

Fatal Error :: Call to undefined method in codeigniter

PHP Classes - Fatal error: Call to undefined method

PHP: Fatal error: Call to undefined method mysqli

Fatal error: Call to undefined function bindParam()

CodeIgniter, adding parameter to form_open function

phpMyAdmin Fatal error: Call to undefined function __()

PHP to Postgres - Fatal error: Call to undefined function pg_connect()

Fatal error: Call to undefined function

PHP Fatal error : Call to undefined function mysql_connect()

PHP Fatal error: Call to undefined function curl_init()

PHP Fatal error: Call to undefined function pdo_query()

Fatal error: Call to undefined function runQuery()

Fatal error: Uncaught Error: Call to undefined function redirect() PHP logout session