[Solved] Transfer data from one page to another

Hello everyone, I’m trying to create a login page and provide the ability to transfer data from one page to another. In the login page, it will check the database in order to see if the input email and password are the same as email and password stored in the database. After checking that, the input email that is equal to email stored in the database should be transferred into another page (main page). Please find below the code in the login page:

// For full API documentation, including code examples, visit http://wix.to/94BuAAs 
import wixData from 'wix-data'; 
import wixUsers from 'wix-users'; 
import wixLocation from 'wix-location'; 
import {session} from 'wix-storage'; 
 
let userEmail; 
let userPassword; 
let user = wixUsers.currentUser;  
$w.onReady(function () 
{  //TODO: write your page related code here...   
$w("#textErrors").hide(); 
})  

export function button1_click(event, $w) 
{  //TODO: write your page related code here..  
let inEmail = $w('#input1');  
let inPassword = $w('#input2');   
let transEmail = inEmail;    
wixData.query("loginDB").eq("email", inEmail).find().then((results) =>   
{  
let resultCount = results.totalCount;    
if (resultCount)     
{       
userEmail = results.items[0].email;       
userPassword = results.items[0].password;   
if (inPassword===userPassword && inEmail===userEmail)       
{           
session.setItem('transEmail', transEmail.value);//Keep in mind, 'item' must be a string.           wixLocation.to(`/mainpage`);       
} else {         
$w("#textErrors").show();         
$w("#textErrors").text = "Incorrect email or password.";       
}} else {       
$w("#textErrors").show();       
$w("#textErrors").text = "Can't find the user.";     
}}).catch((err) => 
{  
let errorMsg = err;
});  
return inEmail;
}  

export function button2_click(event) {  //Add your code for this event here:  }

Here is the code in main page:

// For full API documentation, including code examples, visit http://wix.to/94BuAAs 
import {session} from 'wix-storage';  

let filteredEmailtxt; 
let filteredEmailvle; 
let filteredEmail;  

$w.onReady(function () 
{  //TODO: write your page related code here...
trans_email();     
console.log(filteredEmail, "here is the email being sent to filter");     
console.log("Dataset is now filtered");  
//$w("#transEmail").hide();  });  

export function button3_click(event) 
{  //Add your code for this event here:      
session.removeItem("inEmail");     
session.clear(); }  

export function trans_email(event, $w) 
{  
const transEmail = session.getItem('transEmail'); //Where result will be a string.     
filteredEmail = transEmail; 
}

However, the outcome is: undefined here is the email being sent to filter
So what did I do wrong here?

#transferdata
#transferringdatabetweenpages

You are not retrieving the values from your input fields. You need to do something like this:

let inEmail = $w('#input1').value;  
let inPassword = $w('#input2').value;   
let transEmail = inEmail;    

I hope this helps.

Dear Yisrael,

I am still getting the same error and I already added the input fields in the login page.

I just found another error.

You do not want this:
session.setItem(‘transEmail’, transEmail.value );//Keep in mind, ‘item’ must be a string.
You do want this:
session.setItem(‘transEmail’, transEmail );//Keep in mind, ‘item’ must be a string.

BTW - I know that you have the input fields, but you are not retrieving the values correctly.

not this:
let inEmail = $w(’ #input1 ‘);
this:
let inEmail = $w(’ #input1 '). value ;

Dear @yisrael-wix ,

Well, I made the adjustments that you informed me but still it keeps sending to console that its null. Please find below the amended login page:

import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
import {session} from ‘wix-storage’;
import {local} from ‘wix-storage’;

let userEmail;
let userPassword;
let user = wixUsers.currentUser;

$w.onReady( function () {
//TODO: write your page related code here…
$w(“#textErrors”).hide();
})

export function button1_click(event, $w) {
//TODO: write your page related code here…
let inEmail = $w(‘#input1’);
let inPassword = $w(‘#input2’);

wixData.query(“AttendeeDB”).eq(“email”, inEmail).find().then((results) =>
{
let resultCount = results.totalCount;

if (resultCount)
{
userEmail = results.items[0].email;
userPassword = results.items[0].password;

if (inPassword===userPassword && inEmail===userEmail)
{
let inEmailtrans = $w(‘#input1’).value;
const transEmail = inEmailtrans;
console.log(transEmail, “here is the email being sent to filter”);
local.setItem(‘transEmail’, transEmail);//Keep in mind, ‘item’ must be a string.
session.setItem(‘transEmail’, transEmail);//Keep in mind, ‘item’ must be a string.

    setTimeout(wixLocation.to(`/mainpage?transEmail=inEmail`), 2000) 

//wixLocation.to(/mainpage);
} else {
$w(“#textErrors”).show();
$w(“#textErrors”).text = “Incorrect email or password.”;
}
} else {
$w(“#textErrors”).show();
$w(“#textErrors”).text = “Can’t find the user.”;
}
}). catch ((err) => {
let errorMsg = err;
});
return inEmail;
}

and please find below amended main page code:

import {session} from ‘wix-storage’;
import {local} from ‘wix-storage’;
import wixLocation from ‘wix-location’;

let filteredEmail;
let transEmail;
let inEmail;

$w.onReady( function () {
//TODO: write your page related code here…
let query = wixLocation.query;
if (query.transEmail === inEmail){
let Email = inEmail;
console.log(Email, “here is the email being sent to filter (location)”);
}
Collect_Email();
});

export function button3_click(event) {
//Add your code for this event here:
session.removeItem(“inEmail”);
session.clear();
}

function Collect_Email()
{
let transEmailses = session.getItem(‘transEmail’); //Where result will be a string.
let transEmaillcl = local.getItem(‘transEmail’); //Where result will be a string.
let filteredEmailses = transEmailses;
let filteredEmaillcl = transEmaillcl;
console.log(filteredEmailses, “here is the email being sent to filter (session)”);
console.log(filteredEmaillcl, “here is the email being sent to filter (local)”);
console.log(“Dataset is now filtered”);
}

@mohamed You still have the wrong code:

let inEmail = $w('#input1');
let inPassword = $w('#input2');

You need this instead:

let inEmail = $w('#input1').value;
let inPassword = $w('#input2').value;

You might want to consider using the wix-users API to handle your login. This will result in an easier, seamless, more reliable, and more secure login process.

I tried using the wix-users API, but, for my site it has different features that I’m afraid that wix-user can not provide. In addition, I used the steps on this question forum and I don’t understand why in his situation it worked. Please find below the link to forum:

@mohamed You need to make sure to correctly get the values from your input components. For example:
let inEmail = $w(’ #input1 ').value;
Did you make the changes?

@yisrael-wix , Yes I did. Nothing changed.

@mohamed Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.

@yisrael-wix
Link: https://editor.wix.com/html/editor/web/renderer/edit/5948205c-05fb-408d-9479-938ed51cf498?metaSiteId=5de86ec1-ff40-450b-96a9-7f8dc19278f7&editorSessionId=f3bdde27-286c-4af8-af2a-4816d419bc7f&referralInfo=dashboard

Page: Login and main page.

@mohamed Your Log in button is not connected to the button1_click() event handler. You can connect it like this:

@yisrael-wix It worked! Thank you very much for your help

@mohamed :tada::tada::tada::tada::tada:

@yisrael-wix would you kindly have a look at my second problem?
Please find below the link: