XF 2.0 setting the action on a form

I tired that, but it appears to be empty

PHP:
    public function actionSavePrediction(ParameterBag $params)
    {
    
        $player_id = $params['player_id'];
 
There is, it's hidden, but it's there
<xf:hiddenval name="player_id">{$player.player_id}</xf:hiddenval>

Currently $player_id = $_POST['player_id']; works
 
Here is what I get with var_dump on $params

object(XF\Mvc\ParameterBag)#242 (1) { ["params":protected]=> array(0) { } }
 
better use \XF::dump($params); ;)

So, this works, and $params->player_id does not work?! Sorry, no clue what is happening there...

Could it have anything to do with me using it on the previous page. On the player page I use the ParameterBag to get player_id $player_id = $params->player_id;
 
sorry, still a beginner too..

Try:
$player_id = $this->filter('player_id', 'int');

Interesting..what exactly does this do? Is it the same is mysqli_real_escape_string?

These all worked for me

PHP:
        $player_id = $this->filter('player_id', 'int');
        $college_id = $this->filter('colleges', 'int');
        $confidence = $this->filter('confidence', 'str');
 
It's this method in XF\Mvc\Controller
PHP:
    public function filter($key, $type = null, $default = null)
    {
        return $this->request->filter($key, $type, $default);
    }
It validates the $this->request->field_name property and returns it.

You can also use the $this->request directly. Just try this in your controller:
PHP:
\XF::dump($this->request);
 
Top Bottom