SOLVED: Uploading Multiple Files to Database

I am trying to upload three photos, an email address, and the date into a single database item. I have tried two ways to accomplish this.

First, I have built my form with three upload buttons for photos, an email input field, and a date picker with a button to submit. I have connected all of the user inputs to a field in my database using the database connection feature on each element and setting the button to “submit” to the database.

The result is that it saves all of the elements but does not submit the email field.

Secondly, I have written a page code with out connecting the elements.

This results in each photo getting uploaded to a separate item in the database and the email and date being saved to a fourth item.

Any suggestions for getting this to work so that everything is getting saved to the same item in the database?

1 Like

OK so I solved this by using the first method I described above.

I built the form with three upload buttons for photos, an email input field, a date picker, and a button to submit. I connected all of the user inputs to a field in my database using the database connection feature on each element and setting the button to “submit” to the database.

I was prepopulating the email and date based on the member user. What I was NOT doing was setting the field value for the dataset.

If an element is connected to a dataset, setting the element’s value in code does not set the value of the connected field in the dataset. That means if you use the dataset to perform a submit, the value changed in code is not reflected in the submitted item.

To submit the new value using a dataset, set the field’s value using the setFieldValue() function before performing the submit.

In order to set the field value, I added the following code in the page onReady function:

$w.onReady(function () {

 let user = wixUsers.currentUser;
 let photodate = new Date();
    user.getEmail()
        .then((email) => {
            $w('#datePicker1').value = photodate;
            $w('#input11').value = email;

            $w("#clientPhotos").onReady(() => {
                $w("#clientPhotos").setFieldValue("photoEmail", email);
            });
        })

This set the field value for the email and allows it to be saved to the dataset.

2 Likes