Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not able get post form submit values in codeigniter

Tags:

codeigniter

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.?

like image 727
Ananth Duari Avatar asked Jul 22 '11 05:07

Ananth Duari


3 Answers

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.

like image 128
Ananth Duari Avatar answered Oct 04 '22 02:10

Ananth Duari


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.. :)

like image 40
jim Avatar answered Oct 04 '22 01:10

jim


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/';
like image 27
hasan Avatar answered Oct 04 '22 00:10

hasan