Questions tagged [usermodel]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
0 answers
392 views

Save and log in a user from event callback

I'm trying to build a plugin wherein after a user is created via the normal means via a front end template, the user is immediately logged in. My module is watching for the after save event on ...
MikeJ's user avatar
  • 11
1 vote
1 answer
538 views

Set User's entry field from PHP in Craft 3

From this question, I tried: $user->setAttributes(['products' => $userProductsIds]); return Craft::$app->getElements()->saveElement($user); Where $user is an instance of craft\elements\...
Jorge Anzola's user avatar
1 vote
1 answer
264 views

Batch saving a custom field to multiple users via controller

I have to build a custom plugin for an internal user management system/data export that needs to be able to get triggered from the CP. I basically have to sort a big amount of users (1500+) in a ...
HendrikEng's user avatar
  • 1,064
1 vote
1 answer
574 views

How to pragmatically set registered user status to pending and then manually send activation email

I have 2 front end registration forms. One for normal users and one for admins. In each form I have a hidden input with a group value like so: <input type="hidden" name="group" value="ypo"> In ...
Lukigi's user avatar
  • 565
1 vote
1 answer
157 views

Adding entry type using setContentFromPost

I'm creating a new user using $user->setContentFromPost(). It all works fine except I can't attach an entry to an Entries field. $user = new UserModel(); $user->username = $email; $user-...
Lukigi's user avatar
  • 565
1 vote
2 answers
947 views

Saving Custom Field Values to User Profile

I have a custom user field 'myuserfield' How do I save a value to this field via a plugin in Craft3? Here is my current attempt. $myvar = '12345'; Craft::$app->getUser()->getIdentity()...
David A McInnis's user avatar
1 vote
1 answer
81 views

Craft redirects to domain.tld/domain.tld/ on logout

I have a logout button on my site that points to the logoutUrl. While the logout works and ends the user session, the user is brought to a page with the URL similar to domain.tld/domain.tld/ where ...
stojda's user avatar
  • 163
6 votes
2 answers
3k views

User events in Craft 3

How do I capture user events in Craft 3? I looked at the documentation but couldn't figure it out. I need to capture after user registration events and after user save events. Here is what I tried, ...
Branko's user avatar
  • 497
1 vote
1 answer
175 views

Save Entry Data as CSV and Email it to the Author / Logged in User

I am trying to email some Entry data that they have created in CSV Format to the author/logged in user. I have a controller setup with a frontend form posting an action to the controller: public ...
Graham Winston's user avatar
1 vote
1 answer
125 views

Add Checked Attribute to Custom User Fields on Frontend User Form

I have a multi-select for users to sign up for newsletters. When they edit their profile they need to be able to see which newsletters they are already signed up for. I have the code to output the ...
Chattervast's user avatar
2 votes
1 answer
305 views

Saving/assigning User Group via a plugin

Anyone had experience of assigning a user group when saving or registering a user via a plugin? Tried various combinations of $user->group = 1, $user->group = [1], $user->setGroups([$group]) ...
Cole Henley's user avatar
  • 1,741
1 vote
1 answer
562 views

Variable for User Field

How do I go about using a dynamic value to access a user field value? I have created a form builder for users and dynamically populate the user field based on the question's associated field. <...
ChocolateOrange's user avatar
2 votes
1 answer
707 views

Correct way of showing errors when editing profile via front-end form?

I've been looking at the following resources: https://craftcms.com/docs/templating/user-profile-form Allow user to change or delete their photo for their profile from the front end Front end edit: ...
Robert Tolton's user avatar
0 votes
2 answers
578 views

Is there a way to programatically add a user when no one is logged in

In my controller, I can add new users when a user with the right privileges is logged in via craft()->users->saveUser(), but this doesn't work when no user is logged in. Is "users/saveUser" the ...
Lukigi's user avatar
  • 565
1 vote
1 answer
47 views

How do I set the Post field after manipulation

I'm trying to write a simple plugin that will intercept registration form's data, manipulate it and move it forward. What I'm struggling with is how to set the Post content of a field after the ...
Lukigi's user avatar
  • 565
3 votes
0 answers
414 views

How can I create a dropdown field programmatically with a plugin?

I'm trying to create a Dropdown field and add it to the User field layout. I've successfully created an empty dropdown field (no options) and added it to the User field layout. Here is my current ...
Greg's user avatar
  • 76
1 vote
1 answer
85 views

Fetching "Pending" Users Related To Entry Within Plugin

This works (but only obtains the active users): // get entry $entry = craft()->entries->getEntryById($entryId); // get existing users in field $entry->customUserField->ids(); So in ...
Jarrett Barnett's user avatar
1 vote
0 answers
58 views

Filter conditions on related UserModel in custom Record

My plugin has a custom ResponseRecord with relations to a UserRecord and ElementRecord as follows: public function defineRelations() { return array( 'user' => array(static::BELONGS_TO,...
Frank's user avatar
  • 153
1 vote
1 answer
384 views

currentUser global is null. I can't figure out why

Does anyone know why currentUser would return null? I'm logged in as an admin.. actually the only user. I've cleared cache, logged out and back in, etc. I can't seem to get it to work. I'm trying to ...
Erik's user avatar
  • 306
2 votes
1 answer
143 views

Sharing files with logged-in users

Our client is a builder and they need a way for their contractors to login and upload/download documents about each build (plans, building consents, information etc). They (the builder) also need a ...
Adam's user avatar
  • 23
2 votes
1 answer
138 views

`onBeforeSaveUser` - Access existing user data

I'm trying to run a quick check to see if any of my user's data has changed before saving them. However, I'm running into a situation where I can only access the new data. I can't tell if this is a ...
Lindsey D's user avatar
  • 24k
2 votes
1 answer
129 views

onSaveUser event - cannot redirect or access errors

I've written a plugin which intercepts the user.onSaveUser event. However if the save fails the user is still redirected to the page specified in the 'redirect' parameter/field of the form. How do I ...
Cole Henley's user avatar
  • 1,741
0 votes
1 answer
1k views

Accessing custom fields from User Model

I have a User entries field called 'company'. I'm writing a bespoke plugin to manage users in the front-end and was wondering how I can access the content of this field in my plugin via the user model?...
Cole Henley's user avatar
  • 1,741
3 votes
2 answers
555 views

How to activate a user in a plugin?

I'm trying to activate a user via a plugin so that when the user is returned to the login page they are re-directed to their profile page. I'm making use of the social logins beta plugin by dukt (I ...
Lettie's user avatar
  • 2,033
0 votes
1 answer
154 views

Trying to capture categories field type data in user profile save/update

I am trying to capture the data that is selected when a user selects categories within a categories field type (handle: groups) within the Control Panel profile tab. I was looking thru the Fields, ...
Brad's user avatar
  • 487
1 vote
0 answers
215 views

Uploading a user picture on registration

I would like to make an image upload field so new members are required to upload a picture. I'm new to Craft (I've been a Drupal Front End developer). Other custom fields are working perfectly, and I'...
Jan's user avatar
  • 363
1 vote
1 answer
172 views

Require password from current user on front-end form?

I have a controller that handles some font-end form validation. From that controller I’d like to require the current (already logged in) user’s password to update any field. How can I do that?
James's user avatar
  • 1,138
2 votes
1 answer
118 views

Conditional for user registration fields

What’s the best way to validate a user registration form to make sure that at least one of two fields is not empty? I’ve tried a very simple controller but can’t get this to work past the point of ...
James's user avatar
  • 1,138
1 vote
1 answer
102 views

entry.getAuthor().getGroups() always return empty array

I'm trying to output users groups for every entries in a for loop, but it returns an empty array: {%for entry in craft.entries.section('news') %} ... {{ dump(entry.getAuthor().getGroups()) }} ...
pvledoux's user avatar
  • 133
4 votes
1 answer
476 views

How do I set the user password when using saveUser service method?

I am saving users from an external source and able to create them in the Craft db as users. However, each user's password is set to null despite setting it on the user model prior to saving it. Is ...
Thomas's user avatar
  • 183
2 votes
1 answer
867 views

How to add addition attribute and fields in public registration form in Craft CMS

User Registration Form I want to setup a public registration form in Craft CMS. Currently this form support only fields username, email, password, but I want to add at least 10 other fields. Also I ...
Jawad's user avatar
  • 21
2 votes
1 answer
294 views

Sending email by key to non-user

In a custom plugin, I would like to use Craft's ability to register email message keys in order to keep emails consistent, and I would like to be able to send these emails to users as well as non-...
John O's user avatar
  • 391
3 votes
1 answer
852 views

Searching for users from a plugin

I know how to find user by username and email. The problem comes when I need to query users based on a custom field. Here is my scenario. I have about 2,000 users (part of a user group 'Affiliates') ...
David A McInnis's user avatar
0 votes
1 answer
266 views

How can I return all user custom profile fields in an array?

Hi I'm sure this is simple but it is eluding me. I want to pull out all the user profile fields with twig as an array that I can then check. When I dump the user or currentUser data it does not show ...
Lettie's user avatar
  • 2,033
2 votes
3 answers
1k views

CometChat integration

I need to implement Comet Chat, a facebook-chat-like third-party script, into my Craft project. Comet Chat can connect to most CMS and PHP framework but there is no Craft integration yet, so I tried ...
r-ninja's user avatar
  • 147
1 vote
1 answer
789 views

Update User Profile with Plugin

I'm trying to create a plugin to create/update users' profile data. I figured out how to create a user but updating... not so much. Here is the code I'm using: $user = craft()->userSession->...
Matt V's user avatar
  • 491
2 votes
1 answer
195 views

Processing Business Logic on user.saveUser

I have the following code in my plugin. public function init() { parent::init(); craft()->on('users.saveUser', function(Event $event) { // only fire if new user if ($event->...
David A McInnis's user avatar
1 vote
1 answer
299 views

I cannot get the email address to properly update from my user account management form

I figure I must need to pass the current user's password along with the updated email address upon form submit. However, I cannot get the email address change to take. Any help is greatly appreciated. ...
Herb Himes's user avatar
3 votes
1 answer
141 views

Remove username from photoUrl path

I just realized that Craft puts the username into the path of the photoUrl. Since I use email addresses as usernames, I don’t think it’s a good idea to expose the email addresses of all users on the ...
medoingthings's user avatar
2 votes
2 answers
1k views

Getting the UID of a user model

I want to use the UID to get a user from a url and don't want to use the ID as it is guessable. I know I can do craft()->users->getUserByUid($uid); but after getting the uid, the uid is not on ...
Luke Holder's user avatar
  • 6,827
2 votes
1 answer
574 views

RelatedTo with users

The RelatedTo function keeps puzzeling me. I got it working with categories, but now I want to do something in reverse with users. But I don't fully understand the RelatedTo function. I have a ...
Tom De Smet's user avatar
  • 1,456
3 votes
1 answer
193 views

How do I access the properties of an object which triggered an event?

I'm trying my first plug-in; it's to automatically create an entry in a section when a user belonging to a specific user group is activated. However I'm not that hot at PHP and I can't figure out how ...
Matt Wilcox's user avatar
  • 3,199