I tried a simple form submit But I am not able to get the form values on controller using $this->input->post
as well as $_POST[]
methods. My view part is
<html>
<head>
<title> Feedback page</title>
</head>
<body>
<?php echo form_open('feedback/save'); ?>
<p>
<label>name: </label>
<?php echo form_input('name'); ?>
</p>
<p>
<label>Email: </label>
<?php echo form_input('email'); ?>
</p>
<p>
<label>Feedback: </label>
<?php echo form_textarea('feedback'); ?>
</p>
<p>
<?php echo form_submit('submit','Submit'); ?>
</p>
<?php echo form_close(); ?>
</body>
</html>
and controller part is
<?php
class Feedback extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model("MFeedback");
}
function index() {
$this->load->view('home/feedback_view.php');
//print "loaded";
}
function save() {
print "called";
print_r($this->input);
$name = $this->input->post('uname');
$email = $this->input->post('email');
$feedback = $this->input->post('feedback');
print $name . $email . $feedback;
$this->index();
}
}
?>
I am not sure what went wrong here or is there any config settings I need to look in to it.?
I have found out the problem. It is actually with the rewrite rule. Make sure you have rewrite rule like
RewriteEngine On
RewriteRule ^(application) - [F,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
on root folder of codeigniter.
Take a look at this: http://codeigniter.com/user_guide/libraries/form_validation.html#validationrules
I had a similar issue when I started off using CI. You need to set at least one validation rule for the form and then check to see if the form submitted met that rule. You can then access the submitted form data like you are doing above..
It's been a while since I've used CI but something like this should solve your problem: (Taken from the link above)
$this->load->library('form_validation');
$this->form_validation->set_rules('uname', 'Username', 'required');
$this->form_validation->set_rules('email', 'Password', 'required');
$this->form_validation->set_rules('feedback', 'Feedback', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
if ($this->form_validation->run() == FALSE)
{
// Here is where you do stuff when the submitted form is invalid.
$this->load->view('myform');
}
else
{
// Here is where you do stuff when the submitted form is valid.
print "called";
print_r($this->input);
$name = $this->input->post('uname');
$email = $this->input->post('email');
$feedback = $this->input->post('feedback');
print $name . $email . $feedback;
$this->index();
}
Hope that helps you in someway.. :)
your url address should be same as config->config.php->$config['base_url']
if your url address like
http://www.test.com
then your configh should be
$config['base_url'] = 'http://www.test.com/';
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