Does anyone here ever got empty POST value from submitted form?

2,200 views
Skip to first unread message

Roy H.G.

unread,
Oct 17, 2017, 3:48:47 AM10/17/17
to Fat-Free Framework
Hi F3 users,

Did anyone here got what I face these day?
I already check post_max_size,upload_file_maxsize that recommend from stackoverflow & that is okay..
But I still cannot find any caused made that I cant get the POST submitted value..

Regards,
Roy.

ikkez

unread,
Oct 17, 2017, 4:14:41 AM10/17/17
to f3-fra...@googlegroups.com
well it depends.. have you made a POST request with a "application/json" content type header? In that case it could be that php assigns the data to the raw input stream (php://input) instead of the global $_POST variable... this is likely to happen when using a frontend framework like angular (https://stackoverflow.com/questions/15485354/angular-http-post-to-php-and-undefined).

In such a case, you can find the data in the 'BODY'  framework variable... but I suggest to transform it into the old fashioned way before running the router:

// transform json POST body data
if ($f3->VERB == 'POST'
&& preg_match('/json/',$f3->get('HEADERS[Content-Type]')))
{
$f3->set('BODY', file_get_contents('php://input'));
if (strlen($f3->get('BODY'))) {
$data = json_decode($f3->get('BODY'),true);
if (json_last_error() == JSON_ERROR_NONE) {
$f3->set('POST',$data);
}
}
}

$f3->run();


probably this could go into the framework itself, but didn't see anyone else facing this same problem yet.
And when you say you're sending a form, I think this is perhabs not a solution for you.. but I put it here for the record.

ved

unread,
Oct 17, 2017, 8:45:46 AM10/17/17
to Fat-Free Framework
What @ikkez said in case of json.
If that's not the case, for a "regular" POST, you'll have to make sure the content type is: 'application/x-www-form-urlencoded' in order to have F3 assign it to the POST array.
This is needed for example if you're using javascript's own "new XMLHttpRequest()". It's usually not needed if using jQuery or some other libs. Just use chrome's dev tools network inspector to check the headers of your post request.

Roy H.G.

unread,
Oct 17, 2017, 7:50:01 PM10/17/17
to f3-fra...@googlegroups.com
Hmmm..
Did I had any wrong config here?
is it true ur script is inserted on index.php before $f3->run()? no luck results..
I already check php://input on results routes there was empty results..
I already changed the form enctype from application/x-www-form-urlencoded into application/json but it still no results too..
But I send without F3 framework everything is ok?
I send form using f3 in another apps is ok,with the same class&template..
What I missed something?
I'm using form input in the f3 template basic and send it via f3 route using php
But any of php://input, f3->BODY, f3->POST has empty value..
I tried echo using beforeRoute function it was empty too..
It seems the $_POST value has been reset?
the strange case I faced when I alert the form before send using javascript the value of each input text was there..

Regards,
Roy

ved

unread,
Oct 18, 2017, 5:24:47 PM10/18/17
to Fat-Free Framework
I'm sorry but I understood nearly nothing of your last post.

Please show your html/js form and php code.

Roy H.G.

unread,
Oct 18, 2017, 9:59:22 PM10/18/17
to Fat-Free Framework
<form name='login'' method='post' action='/user/submit'>
<input name='name' type='text' />
<input name='password' type='password' />
<input name='submit' type='submit' />
</form> 

If I point the action into another http:/domain.com/test.php that not used f3 that echoing $_POST var it was succeed..
I still checking how if I point the action into another domain using standard f3..
If I using current action into current domain the $_POST var was empty..

Sincerely,

ved

unread,
Oct 19, 2017, 3:31:50 AM10/19/17
to Fat-Free Framework
That's not enough, please show the php code for the "/user/submit" route

Richard Catto

unread,
Oct 30, 2017, 9:20:26 AM10/30/17
to Fat-Free Framework
Not sure if this will help you, but FWIW here is something to check.


In php.ini there is a setting:

enable_post_data_reading boolean

description:

Disabling this option causes $_POST and $_FILES not to be populated. The only way to read postdata will then be through the php://input stream wrapper. This can be useful to proxy requests or to process the POST data in a memory efficient fashion.

taken from php.ini:

; Whether PHP will read the POST data.
; This option is enabled by default.
; Most likely, you won't want to disable this option globally. It causes $_POST
; and $_FILES to always be empty; the only way you will be able to read the
; POST data will be through the php://input stream wrapper. This can be useful
; to proxy requests or to process the POST data in a memory efficient fashion.
;enable_post_data_reading = Off

Roy H.G.

unread,
Nov 22, 2017, 6:59:17 AM11/22/17
to Fat-Free Framework
Hi!
I closed this topic..
The error raised was confused with http or https scheme and htaccess, 
So It will lesson learn for others if we want to update the scheme sites
thankyou.

Fabs

unread,
Jan 28, 2018, 9:54:36 PM1/28/18
to Fat-Free Framework
Had the same issue. Posted a form using Content-Type "application/json", all my data was in the "BODY" variable. I'm using f3 and plain Javascript, not Angular, not jQuery nor anything else.
This script solved my problem, thank you.

Dev DZ Pro

unread,
May 2, 2023, 6:35:10 AM5/2/23
to Fat-Free Framework
I have the sime probleme ; when i send big file and i already check post_max_size and upload_max_filesize .
Regards,
Rahal.

ved

unread,
May 2, 2023, 9:18:13 AM5/2/23
to Fat-Free Framework
Hi,

That is not enough information.

Please post your html form and the code that handles the form or we can't really help you.

Cheers



Reply all
Reply to author
Forward
0 new messages