Hello community, I need your help, how can I save the current url in a subscription form with database, I need the code since it does not compile me, help please
![](https://static.wixstatic.com/media/a27d24_a826f0e62ce64aaf9e6470b7f24b6a1d~mv2.jpg/v1/fill/w_980,h_482,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/a27d24_a826f0e62ce64aaf9e6470b7f24b6a1d~mv2.jpg)
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
Hello Alfredo,
EDIT: The solution below will not work for you since the product page is basically an iframe.
There is no integration between wix code and the product page yet.
You are getting an incomplete url since the form is inside a lightbox.
To send the correct url to the light box, disconnect the 'Me interesa' button and manually set up the onClick event per the example below.
You will need to send the url to the lightbox using the wixWindow functions:
In your product page:
import wixLocation from 'wix-location'; import wixWindow from 'wix-window'; // ... wixWindow.openLightbox("LightboxName", wixLocation.url);
Use this code for your lightbox:
import wixWindow from 'wix-window'; // ... let receivedData = wixWindow.lightbox.getContext(); //use receivedData to populate the url input box
Current code, working almost 100%, thanks to you Roi
import wixLocation from 'wix-location';
$w.onReady(function () {
let url = wixLocation.url; // Change wixLocation.protocol to wixLocation.url. Should be in $w.onReady scope
$w('#URLcurrent').value = url; // #userInputID represents the id name of your input field, change it to the correct id name
$w("#dataset1").onAfterSave(sendFormData);
});
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
$w.onReady(function () {
$w("#dataset1").onAfterSave(sendFormData);
});
function sendFormData() {
const subject = `A ${$w("#input2").value} LE INTERESA LO SIGUIENTE:`;
const body = `Formulario de inscripción CREA TU ECO-HOME
\URL: ${$w('#URLcurrent').value}
\Nombre: ${$w("#input2").value}
\Teléfono: ${$w("#input3").value}
\Email: ${$w("#input4").value}
\Terreno: ${$w("#selection1").value}`;
const recipient = $w("#input2").value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}
Thank you Roi
this need to rescue the url, the idea is that it is the complete url, but I love you, we are getting closer
Hi,
Here is some changes.
Pay attention to the comments:
$w.onReady(function () { let url = wixLocation.url; // Change wixLocation.protocol to wixLocation.url. Should be in $w.onReady scope $w('#userInputID).value = url; // #userInputID represents the id name of your input field, change it to the correct id name $w("#dataset1").onAfterSave(sendFormData); });
This should work,
Good luck!
Roi
hi Roi
code:
import wixLocation from 'wix-location';
let url = wixLocation.protocol;
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
$w.onReady(function () {
$w("#dataset1").onAfterSave(sendFormData);
});
function sendFormData() {
const subject = `A ${$w("#input2").value} LE INTERESA LO SIGUIENTE:`;
const body = `Formulario de inscripción CREA TU ECO-HOME
\URL: ${$w('#URLcurrent').value = url}
\Nombre: ${$w("#input2").value}
\Teléfono: ${$w("#input3").value}
\Email: ${$w("#input4").value}
\Terreno: ${$w("#selection1").value}`;
const recipient = $w("#input2").value;
sendEmailWithRecipient(subject, body, recipient)
.then(response => console.log(response));
sendEmail(subject, body)
.then(response => console.log(response));
}
ELEMENT ID = URLcurrent (input)
Hi Alfredo,
Did you change the element id in the example to your element id ?
If it's still doesn't work, please paste here the relevant code.
Roi
Hi Tal,
it does not save the current URL, how can I do a GET URL, please help me with the syntax, the idea is to save it automatically in an INPUT
Hi,
To retrieve the current URL, you can use Wix Location API:
import wixLocation from 'wix-location'; let url = wixLocation.url;
If you wish to set the URL to the field, you can use:
$w('#userInputID).value = url;
Good luck,
Tal.