Welcome Guest, Not a member yet? Register   Sign In
How to remove certain parameter in request getPost
#1

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() ?
Reply
#2

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...your-model

PHP Code:
protected $allowedFields = ['name''email']; 
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply
#3

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]);
          }
        }
      }
    
Reply




Theme © iAndrew 2016 - Forum software by © MyBB