desertwebdesigns
desertwebdesigns

Reputation: 1045

CodeIgniter $this->input->post() is empty when values are text, but integers work ok

I'm doing maintenance on a website that another developer created. The client was having some data display issues and I narrowed it down to their input form, or more specifically, the POST data processing. All the fields are TEXTAREA fields and the controller function looks like this:

 85                 $data=array(
 86                         'f_location'=>$this->input->post('flocation'),
 87                         's_location'=>$this->input->post('slocation'),
 88                         't_location'=>$this->input->post('tlocation'),
 89                         'forthlocation'=>$this->input->post('forthlocation'),
 90                         'fifthlocation'=>$this->input->post('fifthlocation'),
 91                         'sixthlocation'=>$this->input->post('sixthlocation')
 92                 );
 93                 $query=$this->admin_model->updatelocation($data);

The updatelocation function in the model is:

 54         function updatelocation($data){
 55                 $query=$this->db->where('id','1');
 56                 $query=$this->db->update('location',$data);
 57                 
 58                 if($query){
 59                         return true;
 60                 }else{
 61                         return false;
 62                 }
 63         }

For whatever reason, whenever I submit any sort of text data through the form, it stores it in the database as a '0'. When I submit integers, it stores the integers directly. To make matters weirder, I just tried to do a print_r($_POST) inside the controller function and if there is any integers, all data is accepted, including text. If all of the fields are text, the $_POST array is empty.

I am not a pro on CodeIgniter by any means, but I can at least work my way around it, and I can't figure this one out.

Here's the list of what I've checked so far:

I'm sure there's a few other things I've tried that I can't think of right now. Oh, and one other weird thing. I have a local development server in my house. When I download the entire codebase to that server, everything works fine. Literally the only change I make is the baseurl in the config so it works locally for me, and then everything works just fine: text, integers, everything. It's only on the remote hosted site that the text won't go through. Any help is appreciated. I'm thoroughly stumped.

EDIT 1: Did some further testing with a var_dump($this->input->post()) as the first action in the controller. When all 6 input fields are text, it returns bool(false). It's as if CodeIgniter isn't recognizing the form data if there is text.

The HTML of the form is:

<form name="addlocation" action="<<<redacted>>>" method="post">
<h2>Add Location data</h2>

<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Firstlocation"  name="flocation">0</textarea> </p>
<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Secondlocation" name="slocation">0</textarea></p>
<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Thirdlocation" name="tlocation">0</textarea></p>
<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Forthlocation" name="forthlocation">0</textarea></p>
<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Fifthlocation" name="fifthlocation">0</textarea></p>
<p><textarea style="margin-left:5px;" rows="3" cols="4" required placeholder="Sixthlocation" name="sixthlocation">0</textarea></p>
<button class="btn btn-success" type="Submit" value="Submit">Update</button1>
</form>

I've tried removing the required, with no luck. The '0' is being pulled from the database as it is the current value. Values are being written to the database, just incorrectly.

Upvotes: 1

Views: 1667

Answers (1)

desertwebdesigns
desertwebdesigns

Reputation: 1045

I found the answer, and it was weird. Nothing to do with CI, the form, the database, nothing. I was doing more googling and found this article here. His problem was he was trying to upload images, which I'm not doing, but at the very least it made me at least consider this. Since the exact same code worked locally for me, I had at one point there is something on the server that is causing this. Running a quick phpinfo() on the server confirmed it, the sites post_max_size was set to 100 bytes. So it wasn't the text that was breaking it, it was how much text. Before fixing it, I confirmed by entering a single letter in each field and it fixed it. Anyways, my local server has a post_max_size of 8M, which explains why it was working. I added a php.ini file to the remote server and set the post_max_size to 8M and everything works fine.

I've been banging my head against the wall for a couple weeks on this issue now. I appreciate everyone who read this and looked into it for me. My second obscure problem in as many days :)

Upvotes: 2

Related Questions