Welcome Guest, Not a member yet? Register   Sign In
Extended model not saving additional fields
#1

I am using CI4 with Shield.  I have extended the shield UserModel to add some additional fields.  The field names match in the form, the model, and the db.  I cannot get the canned Shield registration page to save the additional fields.  There is no entry in the log files, and there are no validation issues.  All of the other fields in the original register form are saving to the db.

Any ideas as to what I am missing here?

UserModel
PHP Code:
declare(strict_types=1);

namespace 
App\Models;

use 
CodeIgniter\Shield\Models\UserModel as ShieldUserModel;

class 
UserModel extends ShieldUserModel
{
    protected function initialize(): void
    
{
        parent::initialize();

        $this->allowedFields = [
            ...$this->allowedFields,
            'first_name',
            'middle_initial',
            'last_name',
        ];
    }


Register form:

PHP Code:
<!-- First Name -->
<
div class="form-floating mb-2">
    <input type="text" class="form-control" id="floatingFirstnameInput" name="first_name"
        inputmode="text" autocomplete="first_name" placeholder="<?= lang('Auth.first_name') ?>"
        value="<?= old('first_name') ?>" required>
    <label for="floatingFirstnameInput">
        <?= lang('Auth.first_name'?>
    </label>
</div>

<!-- Middle Initial -->
<div class="form-floating mb-2">
     <input type="text" class="form-control" id="floatingMiddleinitialInput" name="middle_initial"
           inputmode="text" autocomplete="middle_initial" placeholder="<?= lang('Auth.middle_initial'?>"
           value="<?= old('middle_initial'?>">
     <label for="floatingMiddleinitialInput">
         <?= lang('Auth.middle_initial'?>
     </label>
</div>

<!-- Last Name -->
<div class="form-floating mb-4">
    <input type="text" class="form-control" id="floatingLastnameInput" name="last_name"
        inputmode="text" autocomplete="last_name" placeholder="<?= lang('Auth.last_name'?>"
        value="<?= old('last_name'?>" required>
    <label for="floatingLastnameInput">
        <?= lang('Auth.last_name'?>
    </label>
</div> 
Reply
#2

See https://github.com/codeigniter4/shield/discussions/333
Reply
#3

(12-08-2023, 12:38 PM)datamweb Wrote: See https://github.com/codeigniter4/shield/discussions/333

Step six did the trick.  

Changing the public string to:

PHP Code:
public string $userProvider = \App\Models\UserModel::class; 

Thank you!
Reply
#4

Thanks for the feedback. The documents have been updated.
https://github.com/codeigniter4/shield/pull/977
Reply




Theme © iAndrew 2016 - Forum software by © MyBB