Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

registrationAction not storing custom fields #73

Open
DaveC49 opened this issue Jun 3, 2016 · 0 comments
Open

registrationAction not storing custom fields #73

DaveC49 opened this issue Jun 3, 2016 · 0 comments

Comments

@DaveC49
Copy link

DaveC49 commented Jun 3, 2016

Hi,
i have created an extended User and addeda number of custom fields as described in the tutorial. I found that the custom fields were not being stored in the database on registration. I had also setup validation in the extended User class for these custom fields and i found this was failing because the custom fields were not defined. I noted another users comment that the editAction did allow editing and saving of the custom fields on examining the code for the editAction and the registerAction, I found the code in the UserController::createUserFromRequest() method did not load the custom fields data from the request into the $user instance of the User class whereas the corresponding code in the editAction did. I extended the UserController and overrode the createUserFromRequest() method in the extended controller and added the following code copied from the editAction.

    $customFields = $this->editCustomFields ?: array();

    foreach (array_keys($customFields) as $customField) {
        if ($request->request->has($customField)) {
            $user->setCustomField($customField, $request->request->get($customField));
        }
    }

and then overrode the $app['user.controller'] in my bootstrap file with the extended UserController. This has resulted in the registerAction successfully storing the new user from the registerAction in the database and allowing the validation code I added in my extended User class to run and validate the custom fields in addition to the user table fields.

This seems to have resolved the issue of storing the customFields from the registerAction. It would be perhaps better to include the above code in the SimpleUser\UserController.

Cheers

David Cousens

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant