Question about submission form to database |
I'm pretty new at CodeIgniter. I'm now wanting to create my first submission form to my MySQL database. My database settings are correct in the database.php in the config folder. I know that I need a view page, a controller page and a model page for this task, but I need to see some samples that I can use and test. I found some sample view, controller and model code on this page but I'm getting an error message on my test view page. Below is line 10 in the code. Any ideas what's happening? Or do you know any other places where I can copy the view, controller and model code to try to replicate this on my own site for practice?
PHP Code: <?php echo form_open('insert_ctrl'); ?>
I would recommend you going through the html form at first.
Like, View : PHP Code: <form action="POST" method="<?php echo base_url('/your_controller/lets_post_it');?>"> Controller PHP Code: public function lets_post_it() { MODEL PHP Code: public function upload_it($data){
You don't have the form helper loaded. Load it in your controller constructor.
Simpler is always better
The error that "test view page" displays indicates you have not loaded the "form" helper.
The following line of code is in the example you are working from PHP Code: $this->load->library('form_validation'); It turns out that "form_validation" will load the "form" helper for you. If you are not using "form_validation" in your test then explicitly load the "form" helper in your controller with this line. PHP Code: $this->load->helper('form'); (08-07-2019, 02:30 PM)dave friend Wrote: The error that "test view page" displays indicates you have not loaded the "form" helper.Thanks for the info. Do I replace in my controller PHP Code: $this->load->library('form_validation'); with this below? PHP Code: $this->load->helper('form');
(08-07-2019, 02:45 PM)ronniebel Wrote:(08-07-2019, 02:30 PM)dave friend Wrote: The error that "test view page" displays indicates you have not loaded the "form" helper.Thanks for the info. Do I replace in my controller If you are not using field validation you can (but do not have to) replace library('form_validation') with helper('form'). One or the other must be used.
You load helpers, libraries and models in the controller where you need them. If you need specific helpers, libraries or models in all your controllers, you can autoload them in application/config/autoload.php.
It's a good idea to autoload the url helper, for instance, and also the database library. If you use session variables all over your application, autoload the session library as well. |
Welcome Guest, Not a member yet? Register Sign In |