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>
- I tried to check the data post in Browser and it shows the data that I input in the input box.
- 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] => )
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 Once page loaded, If i edit the name of the input time 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. Dont know why?
Update: I found some this strange. In the set-cookie of the browser. Its 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 destory 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 then 6 set cookies in the browser.
1 Answers
Answers 1
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!
0 comments:
Post a Comment