Auto populate input field and add to 2 or multiple collections on submit

Is it possible to have an input fields data posted to 2 collections when submitted? As I can see I can only connect to one collection for that input field.

I have a form that populates the “User” field with the logged in users email address, works great. I have 2 collections, “Maxlift” and “Maxlift reps”. The user can use the drop downs and submit once they have selected their options. The drop down data goes to it’s specified collection however I have a column in both collections called userEmail that I would like populated automatically. Can I use the PersonalMembersData at all?

I have gone through trial and error for days and just wondering if anyone has any suggestions or if this is even a possibility. Greatly appreciate any help.

Hello Frankie,

in fact i think that you have here 2-questions right?

  1. How to populate with one click into 2-databases? (right?)
  2. Can i use the PersonalMembersData for my needs? (right?)

So i will give you just for one question an answer, because every post should have its specific and unambiguously (clearly) content with just one topic (one problem).

You will need this few codelines, to realize your project.

$w ( ’ #dataset1 ’ ). setFieldValue ( “userEmail” , “my new value” ) $w ( " #dataset1 " ). save ()

$w ( ’ #dataset2 ’ ). setFieldValue ( “userEmail” , “my new value” ) $w ( " #dataset2 " ). save ()

Just about 30min before, there was almost the same issue, look by your self here…

1 Like

Thank you for your help! OK I understand, I’ll remember to use separate posts in future.

Yes, I’m hoping to post the userEmail into 2 different databases. I will attempt your solution and also check out the linked post. Thank you!

That code worked to get the field populated. Thank you so much! The only issue I’m having now is that if a datasets fields are not completed, but the form is submitted, a row is added to the data set but only includes the email address brought in from the code. Is there a way to check and not submit that line?

  • Should i create another post for this?? I’m new, sorry :expressionless:

Hello again,

  1. to show a pic of a code is not the best idea!
    The person who helps you, don’t wanna waste to much time, just by typing all your code manually into the editor. (just copy and paste)
    Better way ----> use the “code-snipet function”, you will find it here…

2) You can show pics of the structure of your database or other things, but not the code.

1 Like
import wixUsers from 'wix-users';
import wixData from 'wix-data';

let user = wixUsers.currentUser;

let userId =;           // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true

  .then( (email) => {
 let userEmail = email;      // "user@something. com"
  $w('#emailinput').value = userEmail;

export function workoutsubmit_click(event) {
    $w('#maxliftdataset').setFieldValue("userEmail", $w('#emailinput').value)
    $w('#maxliftrepsdataset').setFieldValue("userEmail", $w('#emailinput').value)
    $w('#maxliftrepssetsdataset').setFieldValue("userEmail", $w('#emailinput').value)
    $w('#maxliftrepssetsexercisesdataset').setFieldValue("userEmail", $w('#emailinput').value)
    $w('#totalbodyworkoutdataset').setFieldValue("userEmail", $w('#emailinput').value)

OK, i will take a look, if tomorrow anybody perhaps already has helped you.

The problem here is still actual?

Yes :frowning: It is still populates all data sets even if a section is not completed

Hello Frankie,

take a look at this example, i hope it will help you a little bit.

import wixUsers from 'wix-users';
import wixData from 'wix-data';

//------------------------------------ USER-INTERFACE ---------------------------------------
var myDATASET1  =   "#dataset1"
var myDATASET2  =   "#dataset2"
//------------------------------------ USER-INTERFACE ---------------------------------------

$w.onReady(function () {
 let user = wixUsers.currentUser;
 let userId =;           
 let isLoggedIn = user.loggedIn;

    .then( (email) => {
 let userEmail = email;
        $w('#emailinput').value = userEmail;

export function workoutsubmit_click(event) {
    console.log("emailinput-value= " + $w('#emailinput').value)
 if ($w('#emailinput').value!=0) {console.log("Form complete")
        $w(myDATASET1).setFieldValue("userEmail", $w('#emailinput').value)
        $w(myDATASET2).setFieldValue("userEmail", $w('#emailinput').value)
 else {console.log("Incomplete form")}

This will depend on how you are saving the dropdown choice to your dataset, as obviously the users email should always be filled.

Also, it might be a good idea to set your user email input to be read only and hidden on load, so that only you know that it is there and it can’t be edited.

You can simply set the dropdown to be required through the dropdown settings in the editor and add a submit button to your page.

You can then take out the save() function line of code and simply connect the user input fields to your dataset and your code will be saved through the use of the submit button.

If you are wanting to carry on with your own workout submit button with the use of code, then you will need to add the setFieldValue for the dropdown as well, as you are currently only saving the user email field.

For that you can make use of setFieldValues so that you are not repeating your lines of code for each field.

$w("#myDataset").setFieldValues( {
  "title":  "New Title",
  "name":   "New Name"
} );

You can also make use of code and only enable your workout submit button if the dropdown has been used and a value chosen.

Something like this and let the submit button disabled by default.

export function isValid() {
 let email = $w('#dropdown1);
 if (!(email.valid )) {

You can also make use of onCustom Validation on the dropdown to make your code only do something if the dropdown value is chosen, otherwise it is rejected and an validation error message can be displayed.

You can see more about validation here.