14

I'm working with Codeigniter. I have created an HTML form which post data to the Controller.

This Form was working perfectly but it suddenly stopped posting data.

HTML:

<form name="frm_search" id="frm_search" method="post" action="http://ip/free/index.php/taskdetails/tabOne/1/ShibNo/asc/">
<input  id="order1" name="order1" value="26" type="text" >
<input  id="item1" name="item1" value="" type="text" >
</form>
  1. I tried to check the data post in Browser and it shows the data that I input in the input box.

enter image description here

  1. In My index.php I placed the following code to see if it is posted:
echo "CONTENT_TYPE: " . $_SERVER['CONTENT_TYPE'] . "";
$data = file_get_contents('php://input');
echo "DATA: <pre>";
var_dump($data);
var_dump($_POST);
echo "</pre>"; 
exit; 

RESULT:

CONTENT_TYPE: application/x-www-form-urlencoded

string 'order1=26&item1='

array (size=23)
'order1' => string '26' (length=2)
'item1' => string '' (length=0)

But when I print $_POST in controller I get the following:

Array
(
    [order1] => 
    [item1] =>
)
  1. My .htaccess code as follows:

    RewriteEngine on
    
    RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
    
    RewriteCond %{REQUEST_FILENAME} !-f
    
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

Can someone tell me what's the issue? I'm not able to find out why is it when the data passes to controller it becomes null. The application was running successfully for more than a year but I got this issue suddenly.

Thank you in advance. Kindly let me know if you need any more to help me.

Note: I figured out that once the page is loaded, If I edit the name of the input to some other name then the data is post successfully.

i.e: instead of order1, If I change the name my editing using inspect element in Chrome to "neworder" Then if I submit, the data submits with value to controller. Don't know why?

Update: I found some this strange. In the set-cookie of the browser. It's like a full page of junk.

Each time when the page is called i start a new session but i wont kill the existing session. Is that a problem?

Even If i destroy the old session and start new one I get eh set-cookies in browser. It has to me one.. but in my case I get more than 6 set cookies in the browser.

23
  • Maybe u r using order1 somewhere Commented Mar 2, 2016 at 20:12
  • What CodeIgniter version? Do you have XSS filtering turned on? Try making order1 = HELLO. What does echo $this->input->post('order1'); produce? Commented Mar 2, 2016 at 20:41
  • Do you have some jQuery running on the page which is doing $('#order1').val(''); or anything like that? Commented Mar 2, 2016 at 20:53
  • No Nothing like that. I tired giving different values but still no answer. Yes have Jquery in the page but not for order val. Commented Mar 3, 2016 at 5:26
  • 1
    @TomPHP please could you show the full view file as well as the controller? Such of issue happens for duplicate name of input field? Moreover, is it ajax request? Commented Mar 21, 2016 at 6:10

3 Answers 3

5
+50

It could be a .htaccess issue with RewriteRule, according to this CI github post issue https://github.com/bcit-ci/CodeIgniter/issues/242:

if Apache server is used then mod rewrite should be enabled, otherwise redirection will be proper but with empty $_POST.

&

if you don't have a trailing slash on your URL the server will send a 301 redirect which will interfere with POST data.

Your problem could be with

RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Try changing to:

RewriteRule ^(.*)$ index.php/$1 [PT,L]

(from: not able get post form submit values in codeigniter) or try to set:

sudo a2enmod rewrite

Hope it helps!

Sign up to request clarification or add additional context in comments.

2 Comments

Try in to remove the www.from base URL in the config.php, extracted from here (very similar issue): stackoverflow.com/questions/28143654/… or check this other too if this not works: stackoverflow.com/questions/14201815/…
I still think it could be a .htaccess / routes problem, what's your controller name? And the function? could you paste the folder structure or more code (config.php., route.php...)?
1

Hi as par my research about this problem is a very unacceptable type but yet I don't know why this is happening or maybe in Codeigniter have some restriction for this kind of problem.

if you described your base URL in config like this, remember at last of URL not included slash:

http://ip/free/index.php

and on your HTML file on the form tag at the action described like this. remember at last used slash:

http://ip/free/index.php/taskdetails/tabOne/1/ShibNo/asc/

This is occurring problem to not pass any data to the controller because 'slash' change the path.

In this case, if you did not use a slash at last on-base URL then don't use on HTML form also to make it work.

If you face this kind of problem then once try this might help.

Comments

1

I was with the same error and solve like the answer above.

baseURL in the .env file must contain for production something like

https://www.yourwebsite.com.br/ CodeIgniter 4

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.