Welcome Guest, Not a member yet? Register   Sign In
Filters and $_POST (or $request post vars)
#1

I want to automatically add variables to each incoming POST, so I thought filters would be helpful, however, I can't see a way to get to the POST vars in the filter class

PHP Code:
class Filters extends BaseConfig
{
 
 public 
$aliases = [
 
'csrf'    => CSRF::class,
 
'toolbar'  => DebugToolbar::class,
 
'honeypot' => Honeypot::class,
 'postfilter' => PostFilter::class
 ];
 public 
$globals = [
 
'before' => [
 
// 'honeypot',
 // 'csrf',
 
],
 
'after'  => [
 
'toolbar',
 
// 'honeypot',
 
],
 ];

 public 
$methods = [
 
    'post' => ['postfilter']
    ];

 public 
$filters = [];


the PostFilters class:

PHP Code:
class PostFilter implements FilterInterface
{
    public function before(RequestInterface $request$arguments null)
    {
        $_POST['Maint_Userid'] = "plugh";
        $_POST['Create_Userid'] = "plugh";
        return $request;
    }

    public function after(RequestInterface $requestResponseInterface $response$arguments null)
    {
        // Do something here
    }


I've also tried:
PHP Code:
public function before(RequestInterface $request$arguments null)
    {
        $post_request = \Config\Services::request();
        $post_request->Maint_Userid "plugh";
        $post_request->Create_Userid "plugh";
        return $request;
    
PHP Code:
public function before(RequestInterface $request$arguments null)
    {
        $request['Maint_Userid'] = "plugh";
        $request['Create_Userid'] = "plugh";

        return $request;
    
(and a few other variations of the above)

It is adding the varaibles to the RequestInterface $request (from log_messages, I see this). Even the direct $_POST didn't add it to the post vars in the controller.
Where should I be doing this (or how do I make the filters see the $_POST vars and add to them)?
Thanks.
Reply


Messages In This Thread
Filters and $_POST (or $request post vars) - by Kaosweaver - 07-27-2021, 05:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB