1

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.

2
  • this->load->model('studCredModeller') missing dollar sign Commented Jul 27, 2018 at 23:21
  • class name should start with capital letter, create method should be Create, add $ to here this->studCredModeller->saveRecords(); and here this->load->view('nypportal'); Commented Jul 28, 2018 at 1:37

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I'm fairly certain the form helper doesn't need the url helper to work. And if it did, it would say something along the lines of missing site_url or base_url function instead of missing form_open function. If you look in the code for the form_open it directly references the config classes functions rather than using the url helper as an intermediary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.