Adding City to Yii2-User extension

Hello all,

I’d like to add a city field to the user profile in Yii2-User using Google Places Autocomplete API.

I’ve managed to add the field (and hidden fields) to the registration page, I’ve managed to have the hidden fields populated as they should when a city is selected, but I’m just not clear on how to get everything in the database on submission.

Obviously, I need to have the city be created in the DB if it doesn’t exist yet before it’s linked to the profile but I’m not sure how to do that.

My relevant code so far is in the following pastebins :

https://pastebin.com/u/Bennd

If anyone could help, that would be amazing.

Thanks

Benn

it depends which yii2-user extension you are using, if you are using dektrium/yii2-user you can register event callbacks

Thanks ! I am indeed using dektrium/yii2-user. I’m not familiar with these events callbacks, if you have more information, that would be great, otherwise, I’ll look into it ;)

here you go the documentation is pretty comprehensive they have a dedicated page for adding custom fields to profile table

Thanks, I had used that to add (with success :) ) a phone number to the profile :)

I tried using a similar technique for the city, but it’s more complicated due to the fact that I need to create a new object in a different table :)

I guess I’ll keep looking :)