You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
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
The text was updated successfully, but these errors were encountered: