Hi All,
I have been looking for this answer for a few days and cannot get a clear answer. It seems to be a recurrent question from lots of users.
I am trying to create the profile for my users and I need to collect their inputs from 2 pages into 1 row of my database. Please see below:
BackEnd Code:
import wixData from 'wix-data'; let options = { "suppressAuth": true, "suppressHooks": true }; export function dataSubmission(payload){ return wixData.insert('Members', payload,options); }
Code for the first page:
import {dataSubmission} from 'backend/submission'; import wixLocation from 'wix-location'; $w.onReady(function () {
}); export function button8_click(event) { let payload = { fullName: $w('#input1').value, surname: $w('#input2').value, email: $w('#input4').value, telephone: $w('#input3').value, instagram: $w('#input5').value, profilePicture: $w('#uploadButton1').value }; dataSubmission(payload) .then( () => { wixLocation.to('/physical-profile-and-food-choices'); }); }
Code for the second page:
import {dataSubmission} from 'backend/submission'; import wixLocation from 'wix-location'; import {local} from 'wix-storage'; $w.onReady(function () { $w('#texttotal').text = 'calorias'; $w('#buttoncontinue').label = 'Continue'; $w('#buttoncontinue').onClick(() => { //$w('#message').text = $w('#weight').value + $w('#height').value; let value = local.getItem("key"); // "value" let inputValue1 = Number($w("#weight").value); let inputValue2 = Number($w("#height").value); let inputValue3 = Number($w("#age").value); let inputValue4 = Number($w("#dropdown6").value); let total = (((inputValue1 * 10)+(6.25*inputValue2)-(5*inputValue3))+inputValue4)*1.375; if(total > 2500 && total < 3000) { let total = '2500kcal'; } else if (total >2000 && total <2500) { let total = '2000kcal'; } else if (total >1500 && total <2000) { let total = '1500kcal'; } else if (total < 1500) { let total = '1000kcal'; } else { let total = '3000kcal'; } $w("#texttotal").text = total.toLocaleString(); let payload = { objective: $w('#dropdown2').value, gymHome: $w('#dropdown3').label, height: $w('#height').value, weight: $w('#weight').value, age: $w('#age').value, gender: $w('#dropdown6').label, weightGoal: $w('#input7').value, dietType:$w('#dropdown5').label, calories:$w('#texttotal').text }; dataSubmission(payload) .then( () => { wixLocation.to('/profile'); } ); }); });
Any help would be much appreciated
I think the easiest way would be to save your FIRST-PAGE-DATA into Wix-Storage.
Then loading the PAGE-1-DATA on PAGE-2 and joining the rest of PAGE-2-DATA on PAGE-2 .
1) import Wix-Storage-API on your page-1 and 2
import wixStorage from 'wix-storage';
2) create your payload --> onClick-Event and add it to Wix-Storage (local or session).
PayLoad from PAGE-1:
let payload = { fullName: $w('#input1').value, surname: $w('#input2').value, email: $w('#input4').value, telephone: $w('#input3').value, instagram: $w('#input5').value, profilePicture: $w('#uploadButton1').value };
3) SAVING into Wix-Storage:
wixStorage.local.setItem(key, value);
your key --> "whatever-String"
your value = your PayLoad
wixStorage.local.setItem("key", payload);
Maybe you first also want to STRINGIFY your PayLoad before saving it into STORAGE.
let key = "myKey"
let value = JSON.stringify(payload);
wixStorage.local.setItem(key, value);
Your data is now inside Wix-Storage.
4) Now try to get data on PAGE-2 back from STORAGE.
https://www.wix.com/velo/reference/wix-storage/storage/getitem
5) Add more data to your existing payload...
payload.objective=$w('#dropdown2').value payload.gymHome=$w('#dropdown3').label payload.height=$w('#height').value,
6) Save your completed payload to DB...
export function dataSubmission(payload){ returnwixData.insert('Members',payload,options); }