For some reason I cant seem to get to post data in a codeigniter controller. I broke it down to a very simple form to test it out, still no luck. If I use method="get" it works fine. Anyways, below is the form, the controller/function, and my .htaccess. Any help would be much appreciated. Also, I saw a few other similar questions on here, but none of them seemed to have an answer that worked for me.
form:
<form id="bundleOrderInfo" name="bundleOrderInfo" action="<?php echo(base_url()); ?>catalog/bundleSubmit" method="post">
<input type="text" name ="test" id="test" value="blahblah"></input>
<input type="submit"></input>
</form>
controller/function:
public function bundleSubmit()
{
$this->output->enable_profiler();
$this->load->model('catalog_model');
$data['availableCategories']=$this->catalog_model->getCategories();
$data['availableItems'] = $this->catalog_model->getByCategory($data['availableCategories']);
$testing = $this->catalog_model->formData();
$this->load->view('templates/header');
$this->load->view('templates/menu',$data);
print_r($_POST);
}
.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /ITPortal/index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ITPortal/index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /ITPortal/index.php
</IfModule>
action should direct to controller function, if you try FormHelper your life will be much easier
https://www.codeigniter.com/user_guide/helpers/form_helper.html
Try to load models,helpers, libraries at constructor [ __construct() function] it is a good proper way.
Controller
function __construct()
{
parent:: __construct();
$this->load->helper('form'); //loading form helper
$this->load->model('catalog_model'); //loading your model
}
function bundleSubmit()
{
$this->catalogmodel->insertFromForm(); //calling your method from model
}
Normally you should catch Posted Value in model
Model
function insertFromForm()
{
$name= $this->input->post('name');
print_r($name);
die(); // stop the process here
}
View
<?php echo form_open('catalog/bundleSubmit','id="bundleOrderInfo" name="bundleOrderInfo"') ;?>
//you can also do this , this should be enough
//<?php echo form_open('catalog/bundleSubmit')?>
<input type="text" name ="test" id="test" value="blahblah"></input>
<input type="submit" value="Submit"></input>
<?php echo form_close();?>
Addition
'catalog/BundleSubmit' in form mean means your form posted values will goes to to 'controller/function()' and controller will redirect to a method in model 'model/insertDataFromForm"
If you want to know more you can check with CI's table of contents
How things work
https://www.codeigniter.com/user_guide/overview/appflow.html
more info:- https://www.codeigniter.com/user_guide/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With