Hello Wix Team,
I am trying to make a page where the user inputs 2 fields and when the submit button is pressed, it checks those fields with a wix dataset and if it is matched then it should redirect to a dynamic page which is also from wix dataset
I have found this code till now
import wixData from 'wix-data'; import wixLocation from 'wix-location'; export function gg_click(event, $w) { let username = $w('#name').value; let password = $w('#lname').value; wixData.query("Profile") .eq('firstName', username) .eq('lastName', password) //make sure the field names that you search in the query //are the same as the actual fields in the data base. .find() .then((results) => { if (results.items.length > 0) { wixLocation.to(`/profile/` + firstName); // using the wix location API, // make sure you return the full destination URL } }) .catch((err) => { console.log("err", err); }); }
Screenshot:
Please Help me as I have to make this page urgently.
Thank you
What @Yisrael (Wix) tried to tell you, was that you have an error flagged inside your code (I forgot to check that part of the code, sorry):
There you can see firstName being flagged because it was not defined.
Remove all of that code and put just a console.log(), like this:
.then(results => { if (results.length > 0) { console.log("The button has worked and something was found!") console.log(`This was found: ${results.items}`) } else { console.log("The button worked, but nothing was found!") } })
It should be like this:
import wixData from "wix-data" import wixLocation from "wix-location" $w.onReady(() => { $w("#gg").onClick(() => { let username = $w("#name").value let password = $w("#lname").value wixData .query("Profile") .eq("firstName", username) .eq("lastName", password) //make sure the field names that you search in the query //are the same as the actual fields in the data base. .find() .then(results => { if (results.length > 0) { console.log("The button has worked and something was found!") console.log(`This was found: ${results.items}`) } else { console.log("The button worked, but nothing was found!") } }) }) })