0

I am trying to create a data-entry,with controller which inputs the data, displays it and confirm for any edit then uses a method to submit it to the model.

The problem is that in the load the model in the function post_data() the value of $this->input->post() return an empty array.

I am entering the data returning to the get_data function and then displaying it in the data.php in the view. using

data.php in view post the data to the post_data method.

<form id='form'  action="<?php echo base_url("welcome/post_data"); ?>" method="POST" style="display:inline;">           
<input type="text" name="xyz" value="<?php echo $this->input->post("xyz") ?>" />

the controller is

protected $arr;
public function index(){
    $this->load->view('index/index');
    // $this->load->library('Controllerlist');
    // print_r($this->controllerlist->getControllers());
}
public function get_data(){
    echo "matoercod";
    $this->load->view("index/data");        
}
public function post_data(){
$this->load->model("form1","form",TRUE);
 print_r($this->input->post());
    $blue=$this->form->insert_data($this->arr);
    print_r($blue);
    if($blue){
     echo "Successfully added to database"; 
    }
}}

Why does print_r() method return an empty array? $this->input->post() in the post_data method return empty array. if Iam right $this->input->post() should is global to all the method in Controller CI class.

3
  • Kindly clarify which $this->input->post() is not working. Commented Aug 30, 2015 at 7:42
  • the one in the post_data method. Commented Aug 30, 2015 at 7:47
  • Are you sure, that $this->input->post("xyz") has a value? Have you tried to just set a fixed value? Commented Aug 30, 2015 at 9:40

2 Answers 2

1

Your input tag in form doesn't have a name attribute.

<form id='form'  action="<?php echo base_url("welcome/post_data"); ?>" method="POST" style="display:inline;">           
    <input name="xyz" type="text" value="<? php echo $this->input->post("xyz") ?>" />
</form>

Edit: Also the input tag is closed in a wrong way (closing before the value attribute).

<input type="text name="xyz" value="<? php echo $this->input->post("xyz") ?>" />
Sign up to request clarification or add additional context in comments.

4 Comments

Iam really sorry that was a typo.
guess noobness never ends.
Did it helped ? What was the issue ?
nope,still stuck seems like the $_POST values are being lost,in the scope of post_data
0

If you are loading the view data.php in get_data:

public function get_data(){
    echo "matoercod";
    $this->load->view("index/data");        
}

Then how are you accessing the get_data url? If you are just typing it in the browser, then you are not POSTing you are GETing and so $this->input->post is always going to be an empty array.

It's not entirely clear to me how you are calling your method get_data, but you should probably try to alter it so that it more carefully constructs the data you want to be displayed in any view that it loads

public function get_data(){
    $view_data = array(
        "xyz" => "here is some value" // you could get this value from anywhere
    );
    $this->load->view("index/data", $view_data);
}

Then in your view data.php you would want to refer to just $xyz instead of $this->input->post("xyz"):

<form id='form'  action="<?php echo base_url("welcome/post_data"); ?>" method="POST" style="display:inline;">           
<input type="text" name="xyz" value="<?php echo $xyz; ?>" />

Note that second parameter to the view loading function. It's an array and each associative key in the array will be expanded into a variable within your view.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.