On form submit, save info to database and update boolean on another database

Thanks for the help everyone. I’m having a hard time figuring out how to start this.

I have a custom form on a dynamic page, what i want to do is collect the information from the input fields (name, email, description) on submit when a user clicks the button, but i also want a boolean field on a different site content.

I can get either or to work but i don’t know the first place to try to combine these two things.

Any help would be appreciated, let me know if you need me to be way more clearer than this

Hello leofbermeo87,

just ask yourself what the code have to do step by step?

  1. get data from my form (Name, eMail, Discription, boolean-values)
  2. 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.

  1. 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;
	} );
  1. 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;
	} );
  1. 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