Different database depending on option selection in a form.

Hi, I need form data to go to different databases depending on user selection. My client has 3 stores and wants 3 different databases from one newsletter signup form, depending on the store the user chooses as their store. Is this possible?

Yes, you can do this with code.

What do I need to do?

You’ll need to use the insert function of the data API. You could use buttons or some user input element to determine which database to insert the data to.

Hey Paule,

If you have 3 different databases and you wish to enter the information into any-one depending on the user input then you need to do something like this

//Suppose you have a dropdown which determines the database
 
var database; //define a global variant

export function dropdown2_change(event) {
 if($w("#dropdown2").value === 'Option A') {
        database = 'DatabaseOne';
    } else if($w("#dropdown2").value === 'Option B') {
        database = 'DatabaseTwo';
    } else if($w("#dropdown2").value === 'Option C') {
        database = 'DatabaseThree';
    }
}

function insertEmail() { //call this function whenver you need to submit a data
     let data = {
         'email': $w("#email").value //whatever your field keys are
     };
     wixData.insert(database, data);
}