Urgently!!! Help is needed…

Hello! I need help urgently. How can I add data to a collection in another collection? From the scheme presented below, I want to demonstrate my problem. On the page of my site there are windows № 1,2, the data of which displays data from the collection №1. On the same page, there is a window No. 3,4 for entering data into the collection No. 2. This data is entered manually, this is the date and quantity. Direct arrows indicate the connections, and the curved arrows indicate the direction in which the data should be saved.
The problem is that I can not save all the data in one collection because I can not save the data connected to another collection by clicking on the save button. And I need that in the collection number 2 were brought simultaneously all the data displayed in the field number 1,2,3,4. I will be grateful for any help, thanks !!!

Hi,
Do you want to have a DB and datas in DB refer to a form submit page.

For submit page, some of datas will come from another database ?

Hello! No, a little bit wrong. I ask to forgive me, but most likely the problem is that I unfortunately do not know much English, and I write through an online translator. Now I’ll try to give an example on, it’s easier.
Let’s imagine a school. The teacher must report on his work. On his page there is a form for filling out a report for each student. If the teacher introduces each student separately for the subject, day of the week, time, and so on, when the lesson has passed, it will take a lot of time for the teacher. I want to simplify this process. Firstly, it is possible for a teacher to submit such a report directly from a mobile phone by going to the website and to his teacher’s office. There he will have a form on the report page. In the drop-down list, he chooses his name and the day of the week of the classes, all the students who visit him on this day of the week are shown in the table below. This all works through a filter. All these data are in the form of a schedule in one collection, which I attached to the page. But the teacher’s report should be stored in another collection and in another form. All this is on one page.

Now I will try to explain my situation easier: On the page in the data entry window, the data of the collection No. 1 is displayed and displayed, I need to click on the “save” button and this data should be saved in the collection No. 2.

That is, in order to save some data in the collection, you need to type them on the keyboard through the data entry form, and I do not want to use the keyboard, I want to enter this data as they are already displayed in the information input field. But I can not do this because there is already one collection connected to the input (that would be possible to display this data through the filter), and I can not connect the second one, but the information should be saved in the second collection. Question: How to save Surname Name Patronymic from one collection to another, if the collection to which you want to save is not connected to the form.

If I can not explain to the full correct understanding of what I’m writing, I can prepare screens. Please let me know if it’s better to submit pictures.
Thank you very much for your understanding!!!

And to the article about the teacher. This form is needed in order to see from the collection No. 2 how many a certain student passed classes on a certain subject and which teacher and when

I need to save the inscription from the field “input1,2,3,4” to collection 2, but the “input1,2” field is not connected to the collection 2
And in order to keep this record, you need to connect this collection to these fields. But this possibility is not present, as these fields are already connected to another collection

Hi,
If there are any screenshot is better to understand : )

Hi
Too many screenshots are obtained :slight_smile: :slight_smile:
Did, did, and he got himself confused.
According to the idea, it is necessary to carefully study the scheme I introduced.
There, the point is that the straight arrows indicate what they are connected to. The bottom line is to save the information displayed on impu1,2 in the collection 2, while these windows from the form are not connected to the collection 2

Hope I understand your concept,
In my opinion, I guess you may want to create a system for student’s continued.

I suggest it can break down to 3 DB.

  1. For Student * It’s because teachers like editors of website and students like members of website.

  2. For Subject * In a school, course may always need to update or input.

  3. For your Collection 2 * Teachers can go to a page, which only serves editors, combine data from DB1 and DB2 and give comment to the special student
    If you want to let teacher can submit student comment or report by mobile, it means student may also can view their report on their mobile.

For DB1, you can have a look with this link,
https://support.wix.com/en/article/how-to-create-member-profile-pages-with-wix-code

For DB2, it just a simple submit form. If you want to have a page to view the detail of a subject.

For DB3 inspire,
I create a quick demo, the design may not be good : )

A page for report submission. If you also want to know how to block member who doesn’t a teacher of the school, you can give a comment to me : ) Hope the annoying spamming from this forum will not block it.


Remark,
All dropdown may set to connect dropdown list item to relative field in DB. Therefore, you can select the value in DB. Student & subject may not have any copy data, so you will not find repeat student name or subject.

Coding quite simple.

import wixData from 'wix-data';

$w.onReady(function () {
    var day = newDate().toDateString();
    $w("#textInputForDate").value = day;
} );

export function submitButton_click(){
    var student = $w("#studentNameDropDown").value;
    var course = $w("#subjectDropDown").value;
    var date = $w("#textInputForDate").value;
    var amount = $w("#amountTextInput").value;
    
    let toInset = {
        "studentName": student,
        "subject": course,
        "date": date,
        "amount": Number(amount)
    };
    
    wixData.insert("DB3", toInsert).then(()=>{
        $w("successText").show;
    });
}

For showing the data from DB1 to DB3, it only refer to the permission of your DB.

Hope useful. Good luck,
Heson

1 Like

A very good idea, I just wanted to use this method. But I have a slightly different concept related to the introduction of data connected to one collection, from which it is selected by the filter for the data in another collection. Let me give you another example, this will help me to use this function in other issues related to the work of my program.

For a while, we drop the idea of ​​a teacher. Let’s consider another example: In order that in the collection connected to the source 2 you can save the information indicated in the window 1-4 that they should be connected as in this screenshot

But I can not do this, because window 1-2 is connected to data source 1 as shown in this screenshot

How do I save in Data source 2 what is in “input 1-4”?

Hi again,
You just need to code your save button with action click and don’t connect to any dataset.

import wixData from 'wix-data';
//...
export function saveButton_click(){ 
    var David = $w("#input1").value;
    var Mathematics = $w("#input2").value; 
    var date = $w("#input3").value; 
    var amount = $w("#input4").value; 
    let toInset = { 
        "studentName": David, 
        "subject": Mathematics, 
        "date": date, 
        "amount": Number(amount) 
    };          
    wixData.insert("DataSource2", toInsert).then(()=>{ 
        $w("successText").show; 
    }); 
}

Heson

1 Like

You are just a magician :slight_smile:

1 Like

Thanks for your appreciation : )

Enjoy with WiX code

I will start to implement it right now. If I do not get something, let me turn to you again

Welcome : )

Thank you so much

Hello dear Heson Li I followed your example and created a login page for registered users only. Here is the login page:

For clients

This is her code
// За полной документацией по API, включая примеры кода, зайдите на Velo API Reference - Wix.com

$w.onReady(function () {
//TODO: write your page related code here…

});

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w(“#loginButton”).label = “Выйти”;
$w(“#profileButton”).show();
}
else {
$w(“#loginButton”).label = “Войти”;
$w(“#profileButton”).hide();
}
} );

export function loginButton_click() {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#loginButton”).label = “Войти”;
$w(“#profileButton”).hide();
} );
}
// user is logged out
else {
let userId;
let userEmail;

// prompt the user to log in  
wixUsers.promptLogin( {"mode": "login"} ) 
  .then( (user) => { 
    userId = user.id; 
    return user.getEmail(); 
  } ) 
  .then( (email) => { 
    // check if there is an item for the user in the collection 
    userEmail = email; 
    return wixData.query("Members") 
      .eq("_id", userId) 
      .find(); 
  } ) 
  .then( (results) => { 
    // if an item for the user is not found 
    if (results.items.length === 0) { 
      // create an item 
      const toInsert = { 
        "_id": userId, 
        "email": userEmail 
      }; 
      // add the item to the collection 
      wixData.insert("Members", toInsert) 
        .catch( (err) => { 
          console.log(err); 
        } ); 
    } 
    // update buttons accordingly 
    $w("#loginButton").label = "Выход"; 
    $w("#profileButton").show(); 
  } ) 
  .catch( (err) => { 
    console.log(err); 
  } ); 

}
}

export function profileButton_click() {
wixLocation.to(/Members/${wixUsers.currentUser.id});
}

This page for employees :


This is her code

// За полной документацией по API, включая примеры кода, зайдите на Velo API Reference - Wix.com

$w.onReady(function () {
//TODO: write your page related code here…

});

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w(“#loginBut”).label = “Выйти”;
$w(“#profileBut”).show();
}
else {
$w(“#loginBut”).label = “Войти”;
$w(“#profileBut”).hide();
}
} );

export function loginBut_click() {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#loginBut”).label = “Войти”;
$w(“#profileBut”).hide();
} );
}
// user is logged out
else {
let userId;
let userEmail;

// prompt the user to log in  
wixUsers.promptLogin( {"mode": "login"} ) 
  .then( (user) => { 
    userId = user.id; 
    return user.getEmail(); 
  } ) 
  .then( (email) => { 
    // check if there is an item for the user in the collection 
    userEmail = email; 
    return wixData.query("Employee") 
      .eq("_id", userId) 
      .find(); 
  } ) 
  .then( (results) => { 
    // if an item for the user is not found 
    if (results.items.length === 0) { 
      // create an item 
      const toInsert = { 
        "_id": userId, 
        "email": userEmail 
      }; 
      // add the item to the collection 
      wixData.insert("Employee", toInsert) 
        .catch( (err) => { 
          console.log(err); 
        } ); 
    } 
    // update buttons accordingly 
    $w("#loginBut").label = "Выход"; 
    $w("#profileBut").show(); 
  } ) 
  .catch( (err) => { 
    console.log(err); 
  } ); 

}
}

export function profileBut_click() {
wixLocation.to(/Employee/${wixUsers.currentUser.id});
}

All participants are registered, and only I authorize whether they will be registered or not. I also decided to create a dynamic page for each role separately. For the company’s customers separately, and for employees a separate page. This was done so that customers could not enter the page staff, and employees could not enter the page of the clients.

Everything turned out, but I was faced with the fact that registered users can go to any page in spite of their role. I wanted to ask you to help me. How do I make it so that clients can not access the page to employees, and employees could not access the page to clients. I think that, with the permission I give for registration, manually enter the email in the collection for the intended event scenario. Maybe in the code as it can be specified that if the email is in the collection for employees, then the email client is immediately blocked in the collection of employees. Or vice versa. Then I think they can not go to someone else’s page. But I do not know how to write this in code. I would be very grateful if you can help me.

Simply put, I need that any of the registered participants (who have obtained my registration permission) can log in strictly under their role (for example, a client or a company employee) and only on the page intended for him, and if he tries to go to a page that is not intended for him there will be a window where it will be written that there is no entry there and an offer to visit your page.

Hi again,
You need to add a field in your DB to indentify a member who is member or employees.
I guess your page may have a trigger. For example, a button click then going to page you need.

For code inspire,

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
//...
export function navigateToPageButton_click() {
    let identity = $w("#dataset").getCurrentItem().employees;
    if (wixUsers.currentUser.loggedIn && identity === true) {
        wixLocation.to("/pageForEmployees");
    } else if (wixUsers.currentUser.loggedIn && identity === false) {
        wixLocation.to("/pageForNonEmployees");
    }
}

Remark,
If your member system set up perfectly, code will get the status of employees or not * true of false *

I made a separate database for each role

And a separate dynamic page