Submit collection fields to another collection after submit

Hi all -

I hope one of you can help me out. I have a website that has 2 dynamic pages - 1 is a profile page and one is a page for making requests (It is a personal assistant service). Now … on that request page you can choose different options and once you click submit it goes into a collection called REQUEST. In order for me as the admin to see who submitted it and what their email is I need that info to be pulled from the profile, inserted into a user input field on the request page and submitted to the request dataset (hope this makes sense)

This is so the user does not have to reinsert their information on that page every time as they have don that within their profile already.

Anybody got and idea how to code this?

i guess this will do

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

function getnameandemail () {
	let user = wixUsers.currentUser;
user.getEmail() .then( (email) => { 
    let userEmail = email;
     wixData.query("profiledatabase"); // get the item from the database collection.
	.eq("email", userEmail) //here email is the field value of your email
	.find()
	.then((results) => {
		let result = results.items[0];
        let name= result.name;
        $w("#dataset1").setFieldValue("input1", name);//have to hidden inputs and connect them to REQUEST database's name & email field.
        $w("#dataset1").setFieldValue("input2", email);
	        });
		});
}
1 Like
export function button7_click() {
	 getnameandemail (); //run this function on click  
}

Hi,

Thanks so much - somehow the code conflicts with another code of mine and i cannot get it to work. Here is what i had previously

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

$w.onReady(function () {
wixData.query(“PROFILE”)
.eq(“_id”, wixUsers.currentUser.id)
.find()
.then((result) => {
if(result !== null && result.items.length > 0) {
var user = result.items[0];

		$w("#firstName").value = user.firstName; 
		$w("#lastName").value = user.lastName; 
		$w("#email").value = user.email; 
	} else { 
		// Couldn't find user 

This one works however it does not submit to the Request table in the end - any idea?

instead of

 $w("#lastName").value = user.lastName; 

try this

 let result = results.items[0]; 
 let firstname = result. firstName;
 let lastName= result.lastName; 
  $w("#dataset1").setFieldValue("firstName", firstName);
 $w("#dataset1").setFieldValue("lastName", lastName);
 

Like this nothing happens unfortunatly :frowning:

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

$w.onReady(function () {
wixData.query(“PROFILE”)
.eq(“_id”, wixUsers.currentUser.id)
.find()
.then((result) => {
if(result !== null && result.items.length > 0) {
let result = result.items[0];
let firstName = result. firstName;
let lastName= result.lastName;
let email= result.email;
$w(“#dataset1”).setFieldValue(“firstName”, firstName);
$w(“#dataset1”).setFieldValue(“lastName”, lastName);
$w(“#dataset1”).setFieldValue(“email”, email);

} else { 
		// Couldn't find user 
	} 
}); 

});

use the first code i posted and
use the onReady function

 $w.onReady(function () { 
  getnameandemail (); 
  });

hope this helps!