Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
Validation on contents from php://input
JeanAlesi
January 2016
Is it possible to use the validation object to validate contents from php://input?
I did the following:
$_POST = json_decode(file_get_contents('php://input')
, true);
But, when using
$val = Validation::forge();
if ($val->run()) { }
...it always fails.
Harro
January 2016
Accepted Answer
The Input class reads from php://input, there is no need to do this manually. In this case, Input::json() would work fine.
Fuel doesn't use PHP's global variables, which is why your example fails, $_POST isn't used by run().
By default it will use Input::post() (which is not the same as $_POST), if you want to validate anything else, you need to pass it:
if ( ! $val->run(Input::json()))
{
// failed!
}
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
January 2016