Hi I have few questions in mind since i got the access to beta:
-
When using user input element which connected to database , how can i also get the same information sends to the database also to the email box once user submit ? Just to make it clear - I want to get the same information as received in the database to an email box?
-
Adding an external code - just wondering how to add an external script ? I’m not a coder but I feel ok working with code so i’ve tried to add something from outside -
lets say im trying to do something which is pretty simple- do add function to a button that once user clicks on the button, the button takes him 1 page back to previous page ?
Thanks
Yael
Hay yael,
For the email, there is another thread here about the same thing, with code examples of how to use an external email provider and call them. A quick search in the forum will find that.
As for the navigation using a button, just add an on click event handler to the button using the property panel. In the code function that opens, use the location API to navigate to the other page.
It should look something like
import wixLocation from 'wix-location';
export function button1_onClick(event) {
wixLocation.to('/seo name of the other page');
});
Thanks yoav@ Regarding 2 - What if the previous page is not fixed?
Hay Yael,
Do you mean how to link from one dynamic page to another, say the previous or next one?
In order to do so, you need to first decide what is the ordering between dynamic pages (what is the sort order). Lets assume you want to order by tile. In this case, there are two steps to get a button to link to the next or previous item.
Step one - find the url of the next or previous item. You can do so using the Wix Data APIs
Step two - navigate to the next or previous page in the button on click handler.
The code for this looks kind of like the following
let nextLink;
$w.onReady(() => {
let currentItem = $w('#dynamicDataset1').getCurrentItem();
let title = currentItem.title;
wixData.query('my-collection')
.gt('title', title)
.limit(1)
.find()
.then((res) => {
if (res.length === 1)
nextLink = res.items[0].dynamicPageLink;
else
$w('#button1').hide();
});
});
export function button1_onClick(event) {
if (nextLink)
wixLocation.to(nextLink);
}
Note
-
The dynamic dataset name may be different from dynamicDataset1. Select the dataset and check the name in the property panel. You can also set another name there.
-
The name of the field for the link to the items may be different from dynamicPageLink. In the database view (content manager) open the popup menu for the link column, select field properties and checkout the field key. This is the value you need to use here.
-
If the item is the last item, we hide the button.
-
For the previous item, just change the .gt function to .lt (from larger then to lesser then).
Hi Yoav - really appreciate your time! What you meant will be useful that for sure with dynamic pages, but in this case I meant to something much more simple: if someone going to one page and then want to go back to the prevoius page he just visited in - as simple as that , the thing is its not always the same “back” URL.
let’s say im if going from “home” to > “about” and want to go back to previous page, so the previous page is “home”, but if im going “home” > “about” > “services” -and then click on “back” the prevous page is “about” .
So that’s my question , becuase if it was page SEO url I could also connect it in the very simple way via the editor.
Thank a lot!
How, that’s simple.
For that we have the session storage API which allows storing data on a user session.
So the steps are
First, on each page, store the current page in session storage. Best to do so in site code (see the tabs to the left of the coding area)?
The code will look something like (this is on site code)
import {session} from 'wix-storage';
import location from 'wix-location';
$w.onReady(() => {
let history = JSON.parse(session.getItem('history') || '[]');
history.push(location.url);
session.setItem('history, JSON.stringify(history));
});
Next, on any page with the back button, we hide it if there is no history (this is on the page code)
import {session} from 'wix-storage';
import location from 'wix-location';
let history = JSON.parse(session.getItem('history'));
$w.onReady(() => {
if (!history || history.length === 0)
$w('#backButton').hide();
});
Next, on the button on click event, you read the history and navigate to it
export function backButton_onClick(event) {
if (history && history.length > 0) {
let lastPage = history.pop();
session.setItem('history, JSON.stringify(history));
location.to(lastPage);
}
}
Yoav, Thank you very much! I
We’ve just added a new article about sending an email of form submit:
https://support.wix.com/en/article/sending-an-email-on-form-submission