I want to check what is the problem with my $_post['name'] so I wanna check it what is in it, but it says this variable is not define. This problem is a simplified of this one.
messageform_view:
<div id="content">
<?php $this->load->helper('form'); ?>
<?php echo form_open("HomeController/insert_message"); ?>
<p>
<label for="name">Name: </label>
<input type="text" name="name" id="name" value="" size="30" />
</p>
<p>
<input type="submit" value="Submit" />
</p>
<?php echo form_close(); ?>
</div>
message_model.php:
<?php
class Message_model extends CI_Model {
public function add_message()
{
}
}
?>
HomeController:
<?php
class HomeController extends CI_Controller
{
public function index () {
}
public function insert_message()
{
print_r($_POST['name']);
}
}
?>
The Error:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: name
Filename: controllers/HomeController.php
Line Number: 22
remove the below code from the view
<?php $this->load->helper('form'); ?>
in application/config/autoload.php add below code
$autoload['helper'] = array('form');
in controller to check value of form
print_r($this->input->post());die;
use this in view part : you will get the answer
<form action="<?php echo base_url('HomeController/insert_message'); ?>" method="post">
<p>
<label for="name">Name: </label>
<input type="text" name="name" id="name" value="" size="30" />
</p>
<p>
<input type="submit" value="Submit" />
</p>
</form>
in controller get the name field as
$name = $this->input->post('name');
</div>