Allow logged in members to my site to change ownership of added data in database.

Hi Guys

I’m busy with a website that allows users to register as members on my site and then add pets (dogs and cats) to their account by means of text input boxes and specific drop downs (all related to the animal, such as type, age, etc etc) on a page called ADD A PET. This data is stored on a database named registeredmicrochips.

Users who are logged in can add pets (as mentioned above) and view all their added pets on the VIEW MY PETS page. This page shows the pets that have been added to that users account in the same layout as the ADD A PET page and users can scroll through their pets via buttons that I have created (PREVIOUS/NEXT) as well as change the information and save it with a SUBMIT button, which then updates their database entry and finally delete the entry with a DELETE button.

I need one more button that will TRANSFER a specific pets data from one registered user to another. This is needed because we have some registered users who are pedigree breeders that register the pups when they are born and then when they are sold, would like to transfer that pups info to the new owner.

The new owner would have to obviously first register as a member on the site and once the current owner of the animal enters the new owners registered email address (used to register an account on my site) in a text box on the page and then clicks on TRANSFER, the animals account would then be removed off his account in the database and populated in the specified NEW owners account

Please see link to site below:

https://safetagsa.wixsite.com/mysite-1/

This question sure does remind of another previous forum post about the same thing…

As for the answer, it would bring up a lot of issues with transferring user data that is linked to the individual’s unique id and trying to add it to another user.

You would probably be better off adding the content to the new user first and updating that and then deleting the old content from the old user.

This might have to be done manually to avoid any user conflicts or it could possibly be done with code so that it can be done by anybody with access.

Not this one - https://www.wix.com/corvid/forum/community-discussion/changing-the-owner

It was a post very, very similar to this post about pets and they had issues with changing owner and showing all the animals on the page in a sort of repeater style, however they had got the code from a third party pet site that gave them html code to add to the page.

This third party even had their own API which they could have used instead, however they choose to use the html option.

Reading that article fully now I see that this user posted in April and got a reply on it themselves from Povilas Wix Mod at start of August telling them how to do it without the use of hooks now.

Interesting to see if this user has any code that they have tried themselves or are they expecting somebody here to write it all for them.

Please paste up any existing code that you have got so far…

@givemeawhisky Hi, I did in fact post within that discussion a few months back (I think it was in April), but did not create that discussion myself. It was a similar issue (from what I can see) but going back to that post numerous times, there was no direct reply to my question, neither did I get any smarter from following it :slight_smile:

I have zero proficiency in coding and the bit of coding that I have had to do on the site I have managed to figure out, this issue I’m stuck on though, don’t even know where to start.

So as it stands right now, I am able to display/filter pets for the signed in user only (meaning that a logged in user can only view the pets that they have added and can only edit and delete their own “pet profiles” off the database. This isn’t done in the form of a repeater (I did try this previously but could not find a way for the user to update info that was displayed in the repeater). So rather, the individual fields off the database that correspond to that users pet are displayed in text input boxes in the exact same layout as when they add the pets details initially on the ADD A PET PAGE, with buttons at the bottom of the page to go to the next or previous entry, update the information (in case a detail about the pet has changed) or delete the entry completely.

I tried using the update function in a button and thought that the user can change the email address and if that matches to another registers user, it would somehow send that pet record to him. But alas, this did not work. I HAVE however seen that within the database, the ID field is what wix uses to identify the user, but yes, this cannot be altered (as far as I know), but I would assume that this is what one needs to work with to be able to get the user to transfer to pet profile?

Thanks for you help, not expecting someone to write the code for me, but perhaps point me in the right direction to get me started somewhere.

@info38924

Did you read the reply from Dan and try to implement the code onto your site and reading the following posts from other users to which asked how to do it on their own site?

However, as you do say that you have zero proficiency in coding, then this might be a bit of a complex thing to do first off and fully understand.

You can stay on it and see if you can succeed and do it all yourself, which would be a good idea so that you can learn.
https://support.wix.com/en/corvid-by-wix/basics
Wix API Reference - bookmark this as you will use it many times!
https://support.wix.com/en/article/corvid-using-data-hooks
https://www.wix.com/corvid/reference/wix-data.Hooks.html
https://www.wix.com/corvid/reference/wix-data.html#WixDataOptions
https://www.wix.com/corvid/reference/wix-users.html
https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html

Although now as shown on that post, you can now do it like this, thanks to Povilas (Wix Mod)
Now it is possible to update _owner by passing suppressAuth: true option. This works only from backend code.
Examples:
wixData.insert(‘collectionName’, {_owner: “11111111-1111-1111-1111-111111111111”, title: “Custom Owner”},{suppressAuth: true })
wixData.update(‘collectionName’, {_id:“existing document id”, _owner: “11111111-1111-1111-1111-111111111111”, title: “Custom Owner”},{suppressAuth: true })

If you want more help with this new way above from Povilas, then I would suggest doing it in a new post so that it doesn’t get confusing for you and others with the different ways of working with the code getting mixed up.

Although with that you would need to enter manually the id number for both of the needed users each time, unless you can add a query to your collection or they are going to stay as the same users.

Or if you are struggling you can look at Wix Arena and see if there is a Wix Expert there that can help you - Wix Arena

@givemeawhisky Hi, thanks for the reply. I’ve had a look at the mentioned forum again and get a bit lost.

So here’s a question, I’ve had to change the way users submit data onto the database. I’ve added a 3rd party app form from 123formbuilder which allows me to perform certain functions like printing the form and submitting it to different E-mails depending on certain rules that I have set within the app, so i HAVE to use that. The only downfall now is that forms submitted with 123formbuilder’s forms do not actually create an OWNER ID within the database, this stays blank ;/

Subsequently I have had to filter content on the site visible to registered members by means of their E-mail address supplied in the form and cross reference it to their members list E-mail.

So my question is, if I still need a registered member to transfer data from their “profile” on the FRONT END of the page to another registered member

  1. Is this firstly possible
  2. Can it still be done via the workaround in that mentioned forum, but instead of using the OWNER ID, perhaps using the registered E-mail?

I don’t want to give them access to the backend/editor side of the site.

@info38924

No it would still have to be done through the owner id as that is what is connecting everything to the user, this is given to them by Wix when they first signup and stays with them. Can’t use emails as this is a changeable source.
https://support.wix.com/en/article/about-your-database-collection-fields#system-fields
Owner / _owner / Text / A unique identifier for the creator of the item. Used by the permissions model to determine which user is assigned the Site member author role for the item.

For the examples to work you would have to use code as backend files, however you don’t have to provide users or clients access to the backend, the functions themselves run in the backend and pass the info back to the front end.

That is where you use the imports line at the top of your code on your page to call the imports from the backend, like here on the page code for a using SendGrid example.

import { sendEmail, sendEmailWithRecipient } from 'backend/email';

See Yisrael’s (Wix Admin) reply here from a previous post…
See the descriptions for:
public
backend
Public is run in the client - that is, in the browser.
Backend is more private and secure and runs server-side.

As you are running and using owner ids, this has to be done in the backend otherwise you are opening up your website to the public and that is not safe.

Also, go back to this previous post…
https://www.wix.com/corvid/forum/community-discussion/changing-the-owner
…and read Steven Croppers reply as that will give you a great breakdown for you to understand…
First of all if all of the data collection access is managed using backend code you are in a pretty secure place…

As for using 123FormBuilder you don’t have to worry about using the owner id with them, they should still give you a user id number which should be shown in the ID field that you can use.
CMS (Formerly Content Manager): About Your Collection Fields | Help Center | Wix.com

As you can integrate Wix Contacts with 123FormBuilder it should already know which forms come from which Contact etc.
https://www.123formbuilder.com/docs/how-to-set-up-the-123formbuilder-wix-contacts-integration/