verbb / formie

The most user-friendly forms plugin for Craft CMS.
Other
93 stars 68 forks source link

Formie will not update a User, but instead tries to create a new User #1923

Closed MattWilcox closed 1 week ago

MattWilcox commented 2 weeks ago

Describe the bug

We have a "Membership Subscription" form in Formie, where an existing User is logged in. They must fill out the form:

Things work up to that point.

However, we want the integration to change the User's Group if the payment completes sucessfully; going from "Public Member" to "Subscribed". From what I can tell, the settings seem to allow for that use case. However, Formie is always trying to create a new user instead of saving the change to the group membership of the current user.

Screenshot 2024-06-11 at 10 20 07

The email field is required it seems, so we've added it as a hidden field set to the current user.

Screenshot 2024-06-11 at 10 23 38

The integration is set up as follows:

Screenshot 2024-06-11 at 10 20 27

The form is rendered with:

{% set form = craft.formie.forms({ handle: 'sparkUser' }).one() %}
{{ craft.formie.renderForm(form) }}

And the error we get when submitting the completed form is:

Screenshot 2024-06-11 at 10 25 24

Which reads to me as though it's still trying to make a new user instead of updating the current user.

Steps to reproduce

As above

Form settings

Craft CMS version

5.1.8

Plugin version

3.0.0-beta.14

Multi-site?

No

Additional context

No response

engram-design commented 2 weeks ago

This would be because you have nothing in the "Update Element Mapping" setting. You need to select something to be used to compare against an existing user, otherwise how will Formie know how to define an existing user? This'll probably be the "email" field you have mapped.

MattWilcox commented 2 weeks ago

Ahhh, I assumed that the "User Attribute Mapping" would be what is used to find the existing user (which is why i set the email mapping there), and that the "Update Element Mapping" was just for choosing fields you wanted to have updated on the already selected user (which is none in our case).

Not that they were entirely separate things. Will change that and re-rty - thanks.

engram-design commented 2 weeks ago

Yeah, sorry for the confusion there! The tricky thing with that approach would be that you might want to control them independently, so one of the fields might always change (like a Date or something), but you want to match against a user with an email, but if it tries to find a User with that email + date value it'll never match.

I believe I had a similar issue explaining that writing Feed Me at the time 🥲

MattWilcox commented 1 week ago

Makes sense, just a different sense than the one I had in my head, lol! Cheers :)