I have a page where people come and enter their email address, these emails are stored in the database. If the email address exists in the database the user is redirected to a dynamic page, if it doesn’t exist the its taken to a static page. I have written the code below but nothing happens.
import wixLocation from 'wix-location';
import wixData from 'wix-data';
$w.onReady(function() {
$w('#button7').onClick(function () {
const input = $w('#input7').value;
wixData.query('WorkshopResources').eq('Email', input).find().
then(result => {
let numberOfItems = result.totalCount;
if (numberOfItems === 0) {
wixLocation.to("/resources");
} else {
const callsign = $w('#input7').value;
wixLocation.to("/workshopresources/" + callsign);
}
}
)}
)}
)
I have very little experience with coding so please help.
Hello Shripad Joshi,
well there are a few problems in your code.
Let’s collect some facts…
- You have a site with a user-form
- You have a data-collection, called ??? —> ( " WorkshopResources")
- In this data-collection you have a reference, called —> (“Email”)
- What is —> (“callsign”) ???
Do you have a pic of your site/project, so everyone can imagine better what you see?
Do you also have a pic of your data-base (just the first 2-lines are needed).
Hi Dima,
Yes the site has a form and the database is called “WorkshopResources” with a reference called as “Email”, the callsign is just a constant that takes the input value. This is the form where I take the input from the user
This is how the database looks like:
Thanks for the reply.
Hello again,
check this out. Copy this code and put it into your site.
Look at the structure of the code.
Try always do codings with clear structure, so that the code is better reable!
import wixLocation from'wix-location';import wixData from'wix-data';$w.onReady(function() {})exportfunction button7_click(event) {let EmailInput = $w('#input7').value; console.log(EmailInput) wixData.query('WorkshopResources') .eq('Email', EmailInput) .find() .then(result => {let numberOfItems = result.totalCount; console.log(numberOfItems)if (numberOfItems === 0) { wixLocation.to("https://www.ebay.com"); } else {let callsign = ".com/"//---> deaktivated //$w('#input7').value; wixLocation.to("https://www.google" + callsign); } })}
And here a little EXAMPLE 4 you:
https://russian-dima.wixsite.com/meinewebsite/page-redirection
Thanks for the reply and the example. I tried doing this but I am getting a parsing error
@sp_shripad
Try this one…
import wixLocation from 'wix-location';
import wixData from 'wix-data';
export function button7_click(event) {
let EmailInput = $w('#input7').value;
console.log(EmailInput)
wixData.query('WorkshopResources')
.eq('Email', EmailInput)
.find()
.then(result => {
let numberOfItems = result.totalCount;
console.log(numberOfItems)
if (numberOfItems === 0) {
wixLocation.to("https://www.ebay.com");
}
else {
let callsign = ".com/" //---> deaktivated //$w('#input7').value;
wixLocation.to("https://www.google" + callsign);
}
})
}