verbb / formie

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

Repeater Data > User Data Integration #1888

Open DynamiteGoesBoom opened 1 month ago

DynamiteGoesBoom commented 1 month ago

Question

So I have a couple of repeater fields with a First Name and a Last Initial in my form. I have one for a Student and another for a Teacher.

What I would like to happen is when someone fills out a Form then a User will get added for a Student and another for a Teacher. I had something working awhile ago that took the First Name and Last Initial fields and I dynamically created the email based on that. Something like DeclanB@notarealemailaddress.com. The users will never need to login since we just need those values to display on the Projects structure.

I realize that this isn't a typical situation and I'm hoping you can help me with some options. I think I had a hidden field that got populated in order to prep the data in order to create the user.

I'm not sure what the best way to get that data into an Entry but was thinking that a Student Select or Teacher Select (both User fields with Student/Teacher groups would possibly work.

I hope I explained myself and looking forward to hearing your thoughts. Let me know what you think and thanks for all that you do for the community 🎉You can see the live version here without any of those fields here https://data.bop.nyc/symposium/submit-your-project and hopefully that helps you visualize it.

When used this field would create a Student

Screenshot 2024-05-16 at 12 55 03 PM

When used this field would create a Teacher

Screenshot 2024-05-16 at 12 54 48 PM

Thanks again!

Additional context

No response

engram-design commented 1 month ago

Repeater data in general is a little tricky, and when we're talking about mapping them to an integration, that's not how they work at the moment. Element integrations typically run on the assumption of creating one element from one submission. We would need to alter the behaviour to act on the Repeater rows in the submission.

The second part of generating your email for users. We could add functionality to make this dynamic in the mapping section down the line. Currently, you can only pick a single field to map against, but there's a FR to make that much more flexible. You could also achieve this a number of different ways, from JS to a PHP module, to a Calculations field. Not sure which option you went with.

It's honestly probably just as easy to set up an event listener in a module to when the submission is created, to create those two (or more) users in a module. That way, you can handle your auto-generation of emails, and create Student + Teacher users in one go.

There's also the known issue of validation for element integrations, which needs to be addressed

This could also be related to an idea

So in summary, I would probably recommend using a module to do this work! The benefits are you can do your logic in one place, and can return any validation errors on the user-creation as it'll be performed outside the queue.

DynamiteGoesBoom commented 1 month ago

@engram-design thanks for the info and that's pretty awesome what users are doing with your stellar plugin. I'll play around with some other workarounds and discuss this with the team.

Ahh! Yeah I think it was a calculations field that I was using. This particular form doesn't have a ton of action on it. It's essentially just a way the teachers and children can submit their projects. But of course, we're trying to make it as easy as possible for them to manage the entries.

If you have any other insight or advice to make this easier for them that would be great. We're even considering just using a Text field that adds the Teacher and Students in two separate fields. Maybe the calculation field could help tie those repeater fields to that approach instead of attempting to create the users instead?

Thanks again 🎉

engram-design commented 1 month ago

Even with that latter approach with two separate fields and a Calculations field, you're still trying to create multiple users on a single submission, which isn't possible in Formie. Short of creating two different User element integrations - one for each user you want to do. But then being in a Repeater, it could be more than 2, so that approach won't work.

As I mentioned, I believe module code is the way to go here. Just let me know if you need an example on how to go about it!

DynamiteGoesBoom commented 1 month ago

@engram-design thanks for the info! I'm rethinking this approach and was curious what you thought about this instead:

Would it be possible to have two hidden fields that would just add Student Names (maybe one per line) then have another for Teachers doing the same thing?

This would bypass the User creation and would be far simpler when integrating the Formie submissions with the Projects' entry data.

Would this work?

engram-design commented 1 month ago

I suppose that's possible. A hidden field won't have line breaks though. Or do you mean hidden fields in the Repeater row? You could also use a Calculations field that concatenates the fields and is set to be visually hidden.

I'm still not 100% sure on your use-case though, so tricky to guide you. I was under the impression that you needed to create these users from that data, using the User integration?

DynamiteGoesBoom commented 1 month ago

@engram-design so the User idea I thought would have been nice for the Admins but they don't really need anything that fancy. They're a small outfit that just needs a simple way to collect student projects and be able to share who participated in it and what. teacher(s) were part of it. So the users part would be a nice to have. I think that just collecting the names and providing a way for us to push that through as entry is all we're looking for.

I guess another option would be to use JS to grab the data through a hidden field. I'd like to avoid using JS if possible. Thanks again for the help _insert_rubber_ducky_emoji_here 😹