bmacnaughton Posted March 5, 2015 Share Posted March 5, 2015 I create a new user, add some custom properties to it, and save the user to the DB. But it appears that the custom properties are not saved to the DB. Is this expected behavior? What should I do to save custom properties in the DB? $u = new User(); $u->name = $form->get('username')->value; $u->pass = $form->get('password')->value; $u->email = $form->get('email')->value; $u->addRole('guest'); // add custom fields $u->validation = $validation; $u->timestamp = time(); // i can see in the log that the $user object has validation in it $log->save("wrote validation: $validation to user (\$u->$u->validation)"); // save the user to the DB $u->save(); Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 5, 2015 Share Posted March 5, 2015 I think you didn't add those fields to the user template? If so you can still add variables like above, but these are runtime only and won't be save, as there are no columns in the database for these fields. You can add fields to the user template like you'd do it with every other template. It's just hidden by default so you need to enable "show system templates" on top of the templates-list. 2 Link to comment Share on other sites More sharing options...
bmacnaughton Posted March 5, 2015 Author Share Posted March 5, 2015 Thank you. The show system templates helped. Link to comment Share on other sites More sharing options...
JeevanisM Posted November 10, 2019 Share Posted November 10, 2019 Hello, I have created a standard field type as userphone , then I added this field to the User template. I created a phone field type using Phone Field module. I added this field to the User template also. Now I used the below to create a test user $u = new User(); $u->of(false); $u->name = "saarun"; $u->email = "saarunthomas@example.com"; $u->pass = "123456"; $u->Phone = 9446196667; $u->userphone = 9446196667; $u->headline = "hello there"; $u->paid=1; $u->addRole("registered"); $u->save(); $u->of(true); and I tried to out put as below $item = $users->get("saarun"); echo $item->email; echo $item->Phone; echo $item->paid; echo $item->headline; echo $item->userphone; and I got the output a below. Neither the userphone value nor the Phone value are output ... what am I doing here wrong ? pls help Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted November 13, 2019 Share Posted November 13, 2019 Hey, @JeevanisM! You use an Integer Field for the phone number. Maybe that field cannot store such a big number as 9446196667? Test it with a 123 to check. I guess you should store a phone number in some other field any way. Text would be ok (with some frontend and server validation). There are dedicated fields for this as well like this one. 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 18, 2019 Share Posted November 18, 2019 On 11/13/2019 at 8:59 PM, Ivan Gretsky said: I guess you should store a phone number in some other field any way. Text would be ok (with some frontend and server validation). I'd strongly suggest that as well. A telephone number is not a "number" in the mathematical sense. You'll not do arithmetic on them, leading zeros are not optional, even though it's comprised mostly of digits there might be characters as well, …. Telephone numbers are actually identifiers and those are best stored in text or more specialized columns. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now