Unable to Save Data to Wix Collection from Frontend - Object Returning Empty Values

Hello everyone,

I’m trying to save data to a Wix collection from the frontend. I’ve already created the collection in the Wix dashboard and set the backend permissions function
to allow anyone to insert data. However, when I try to save the data using an object from the frontend, the object always returns empty values.

Here’s an example of my setup:

here is what I get when send the data, it always comes back with empty fields
even when value is given to the input fields, how can I fix this

Have you tried using async await, could be the the function is completing before the object data is actually returned.

Have tried that,

but the object is still returning empty data fields, I even replaced the
object with dummy data like this and it works

but doesn’t work when I try to get the value of the input, it returns empty

So what’s in the registerUser() function that should be returning your result

I am trying to get the input value ( from a form) so when a user fill it out I can get the details, I tried using an object since there are a lot of details, but. it returns null, the register() function is from the backend js file to save data to my collection

I have not used wix forms. But just having a Quick Look ,
They appear to do all of this out of the bag, saving the submission into a collection created when you add a form to page.

I had a play with a custom form and saving its data to a CMS.

It is pretty easy to do without using the backend etc…!

If you really need to send the data to another collection other than the one automatically created for the form.

You can add similar code to the pages code.

import wixData from 'wix-data';

$w.onReady(function () {
    // Add a submit event listener to the form
    $w('#form1').onSubmit((values) => {
        console.log('Trying to submit the form with the following values:', values);

        // Insert data into the collection
        wixData.insert("myCollection", values)
            .then((item) => {
                console.log("Data successfully inserted into myCollection:", item);
            })
            .catch((err) => {
                console.error("Error inserting data into myCollection:", err);
            });

        // Allow form submission to proceed
        return true;
    });
});

But on coming back here, I realise you are trying to do this with member data , is that right?
Why do you need to do this if so ?.

I am not sure that’s normal practice and may be a security risk!?.
Apart from any security considerations regarding a CMS storage. (I’m not an expert ) but for instance, I assume your code would not be encrypted or secure and would expose these details including password etc in the clear?.

Member info is already stored in I assume a more secure area where you can view and manage it via the dashboard’s contacts area from what I have just looked at.

But maybe someone else can throw some light onto this…

Thanks for your help! I’m currently working on building a custom registration function using Wix Members and Data. I have several custom fields that need to be filled out, which aren’t supported by the default Wix Members functionality(I have tried adding custom fields, but it only saves email and password). I do want to hash the password using bcryptjs, that is why I am using the backend.

What is the rest of the code?

Did you use Wix Form app or custom input elements? Are the input elements connected to a dataset? Is the button connected to a dataset?

How are you triggering the code? After form submission? Because all of the fields reset upon submission so you will only ever have empty values.

I’m not using Wix Forms; instead, I built a custom registration UI because I have a lot of custom fields that need to be saved to Wix Data Collections.

the initial code works fine Just when I try to use $w(‘myInput’).value in an object
it returns empty Fields


and this is the result I get

Just try using $w(‘MyInput’).value with an object like this
const data = {
email: $w(‘#MyInput’).value
};

console.log(data);
I’ve tested this approach on other Wix Studio sites, but the input fields still returned empty values even when they were filled from the User.

You can customise the member sign up form.

Thanks for all your help, I found the error! The issue was that I needed to use the object inside the function to ensure it captures the current user input values. Here’s how I fixed it