Hello leofbermeo87,
just ask yourself what the code have to do step by step?
- get data from my form (Name, eMail, Discription, boolean-values)
- save the data into my database
I think there are several ways to to that.
Either you do it with a Collection-query, or you do it with the help of a dataset.
So if you already use a dataset, then do it with the help of dataset, else do it with a collection-query.
wixData.query("myCollection")
.find()
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0]; //see item below
} else {
// handle case where no matching items found
}
} )
.catch( (err) => {
let errorMsg = err;
} );
here you have several options, which one fits the best into your project, you have to decide yourself.
- example with save-command…
import wixData from 'wix-data';
let toSave = {
"title": "Mr.",
"first_name": "John",
"last_name": "Doe"
};
wixData.save("myCollection", toSave)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
- example with update-command…
import wixData from 'wix-data';
// ...
let toUpdate = {
"_id": "00001",
"title": "Mr.",
"first_name": "John",
"last_name": "Doe"
};
wixData.update("myCollection", toUpdate)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
- and an example with insert-command…
let toInsert = {
"title": "Mr.",
"first_name": "John",
"last_name": "Doe"
};
wixData.insert("myCollection", toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
And here an example with dataset…
$w("#myDataset").setFieldValue("title", "New Title");
$w("#myDataset").save();
And here you can see an example, how to save boolean-values into database…
https://russian-dima.wixsite.com/meinewebsite/switch-safe-function