shalom from israel ! I really need some answers here since 4:00am I sit here trying to get data from custom form that one of the inputs is dropdown with two options: option a, option b. now!
If anyone that is filling the form will choose option a: all the data will be save to collection a thru dataset a, If they will choose option b, all the data will be save to collection b thru dataset b.
is that possible ? pls don’t tell me hook cause it is not the case.
You can’t connect a form to two datasets, and you can’t connect to a dataset using code. However, you can save the data with code using the Wix Data API . After clicking the form’s Submit button check what option is selected in the dropdown. If option a, then save to one DB collection, and if option b, save to the other DB collection.
if ($w( “#dropdown” ).value === “a” )
{$w( “#dataseta” ).save()}
else
{$w( “#datasetb” ).save()}
the problem is that the form elements should be connected to any dataset…
They only need to be connected to a dataset if you are saving using a dataset. However, in your case, since you can only connect to one dataset, you will need to save using code in order to save to two different collections.
I did it israel, the information saved only on the form that connected, and in the code it saved empty fields on the second database
Share your code so we can see what you’re doing. You really should disconnect and save both options using code.
$w( “#registrationButton” ).onClick((event) => {
console.log( “button was clicked” )
$w( ‘#errorMessage’ ).hide();
$w( ‘#emailExists’ ).hide();
if ($w( “#fathersName” ).valid && $w( “#mothersName” ).valid && $w( “#gender” ).valid
&& $w( “#theneed” ).valid && $w( “#email” ).valid && $w( “#password” ).valid && $w( “#firstName” ).valid)
{
let email = $w( “#email” ).value;
let password = $w( “#password” ).value;
let first = $w( “#firstName” ).value;
let fathersname = $w( “#fathersName” ).value;
let mothersname = $w( “#mothersName” ).value;
let need = $w( “#theneed” ).value;
let gender = $w( “#gender” ).value;
wixUsers.register(email, password, {
contactInfo: { "firstName" : first
}
})
.then ((result) => {
if ($w( “#gender” ).value === “man” )
{$w( “#mandataset” ).save()}
else
{$w( “#womandataset” ).save()}
$w( “#maindataset” ).save()
.then ((item) => {
wixLocation.to( “/home/” );
})
. catch ((err) => {
let errMsg = err;
});
})
. catch ((err) => {
let errorMsg = err;
console.log(err);
$w( ‘#emailExists’ ).show();
});
console.log( “trying to register” );
} else {
$w( ‘#errorMessage’ ).show();
console.log( “missing information” );
}
});
})
You are using Dataset incorrectly. When I said you would need to save using code, I meant that you would need to use wixData.save() , and NOT the dataset.save() function. Your second dataset is empty, since none of the fields in the form are connected to it (because they are connected to the first dataset). So when you save, it saves an empty item.
You will need to use create an object containing the fields to save in the collection, and then save using the wixData.save() function,. See the sample code snippets in the wixData.save() API .
thank a lot I think I understood, last point to make it clear pls, { If anyone register the form will choose option a: all the data will be save to collection a thru dataset a, If they will choose option b, all the data will be save to collection b thru dataset b} how these explanations feet’s it?
You should not be using datasets to save, you should be using the wixData.save() function.
-
If someone registers and chooses option a , you need to save to collection a using the wixData.save() function.
-
If someone registers and chooses option b , you need to save to collection b using the wixData.save() function.
I really appreciate it thank you very much
לא ברור, צד ימין בירוק אמור להיות title#
אח"כ firstname# , נכון? כי זה נלקח מהטופס שממלא
המשתמש… ובצד שמאל אני מבין אלו שמות העמודות אליהן נכנס התוכן.
וזה נעשה פעם אחת למשתמש אחד, נכון?
Sucssess ! Amazing. Saved directlly to the collection database! Thank you