I’m having trouble sending data from a form submission to two different collections that are connected through a reference field.
For more context, my website is designed to showcase films submitted by local filmmakers.
I’m creating a form where filmmakers enter their film metadata, including the film credits. Since the number of film credits strongly varies from film to film, I’ve added them in an input repeater.
I now have two collections:
-
metadataSubmission (to collect the film metadata)
-
creditNames (to collect the film credits)
I am using a reference field in the metadataSubmission collection named “creditFullName” to connect the films to their credits in the creditNames collection.
For each new film submission, there will be one new row in the Metadata Submission collection. For each row in the Metadata Submission collection, there will be multiple rows in the Credit Names collection.
Here is the code I have for saving the data to the two collections:
import wixData from "wix-data";
import wixLocation from 'wix-location';
export function insertMetadataSubmission(creditFullName, $w){
let metadataSubmission = {
"filmTitle": $w("#filmTitle").value,
"firstName": $w("#firstName").value,
"lastName": $w("#lastName").value,
"emailAddress": $w("#emailAddress").value,
"filmRuntime": $w("#filmRuntime").value,
"releaseYear": $w("#releaseYear").value,
"linkToFilm": $w("#linkToFilm").value,
"filmLogline": $w("#filmLogline").value,
"creditFullName": creditFullName._id,
"selectedGenre": $w("#selectedGenre").value,
"additionalGenre": $w("#additionalGenre").value,
"selectedMood": $w("#selectedMood").value,
"additionalMood": $w("#additionalMood").value,
"keywords": $w("#keywords").value,
"bts1": $w("#bts1").value,
"bts2": $w("#bts2").value,
"bts3": $w("#bts3").value,
"bts4": $w("#bts4").value,
"bts5": $w("#bts5").value,
"behindTheFilm": $w("#behindTheFilm").value,
"promo1": $w("#promo1").value,
"promo2": $w("#promo2").value,
"promo3": $w("#promo3").value,
"promo4": $w("#promo4").value,
"promo5": $w("#promo5").value,
"promo6": $w("#promo6").value,
"promo7": $w("#promo7").value,
"promo8": $w("#promo8").value,
"promo9": $w("#promo9").value,
"promo10": $w("#promo10").value,
"suggestedHashtags": $w("#dogweight").value,
"confirmationCheckmark": $w("#confirmationCheckmark").value,
"status": "PENDING"
};
console.log("metadataSubmission to be saved" + JSON.stringify(metadataSubmission));
wixData.insert("metadataSubmission", metadataSubmission)
.then( (results) => {
let metadataSubmission = results; //see item below
console.log("metadataSubmission in db: " + JSON.stringify(metadataSubmission));
} )
.catch( (err) => {
let errorMsg = err;
} );
}
export function submitButton_click(event, $w) {
let creditNames = {
"name": $w("#creditNameInput").value,
"instagram": $w("#instagramInput").value,
"creditType": $w("#creditsDropdown").value,
"submitting": false
};
console.log("creditNames to be saved" + JSON.stringify(creditNames));
wixData.insert("creditNames", creditNames)
.then( (results) => {
let creditFullName = results; //see item below
console.log("creditNames in db: " + JSON.stringify(creditFullName));
insertMetadataSubmission(creditFullName, $w);
} )
.catch( (err) => {
let errorMsg = err;
} );
wixLocation.to("/thank-you-film-metadata");
}
I tried following this example: https://www.wix.com/corvid/forum/community-discussion/how-to-insert-a-data-in-two-collection-from-a-form
However, for some reason, the user input is not being saved in the collections.
I noticed an error that says, "metadataSubmission is already declared in the upper scope.”
Is this the issue? I’m new to coding - any suggestions on how to fix this?
Or is there a better solution for connecting the two collections?
Link to page: https://www.bayareafilmmakers-arthouse.com/film-metadata
Thank you!