Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Validation on contents from php://input
  • 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.
  • HarroHarro
    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!
    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion