CodeIgniter Forums
How to remove certain parameter in request getPost - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How to remove certain parameter in request getPost (/showthread.php?tid=78371)



How to remove certain parameter in request getPost - basahbasahan - 01-09-2021

I want to update a data in a model, with parameter from user form request post. How can I filter that only certain field that can be updated by removing some parameters in getPost() ?


RE: How to remove certain parameter in request getPost - includebeer - 01-10-2021

Pass all the getPost() data but set the allowed fields in the model. Everything else won’t be updated.

http://codeigniter.com/user_guide/models/model.html#configuring-your-model

PHP Code:
protected $allowedFields = ['name''email']; 



RE: How to remove certain parameter in request getPost - cantinsertdata - 01-10-2021

If you're attempting to filter out fields that are defined in $allowedFields but you don't want an end user to somehow find out about them and then use them maliciously in a crafted request, you can just iterate over the data returned by getPost in a foreach statement, compare the key, and determine if it's allowed to stay.

PHP Code:
    foreach ($data as $key => $value) {
      if ($key !== 'username') {
        if ($key !== 'password') {
          if ($key !== 'referred_by') {
            unset($data[$key]);
          }
        }
      }