Automatically insert the url in the form

Hello !

I am manually making a form in order to comment the feelings of the visitors.
The form is basic !
NAME COMMENT SEND
Those informations are going in a database called “comments”. The name goes in the “name” field, and the comment goes on the “comment” field.
For practically reasons, I would like to put the url of the current page in a “url” field. However, I don’t want for the visitor to manually insert it. So how, without the interaction of the user, I can add the url to the infos sent by the user ?
Thanks for the help !
Vincent

PS : If you want to see it, the form is at the end of the page https://www.vudecypres.com/copie-de-au-dessus-de-la-brume
PS2 : I already tried a “read-only” box with the url put in it, but as it is not put but the user, the wrting process in the database doesn’t include the URL.

Hi,
You can use the Wix Location API to set the current URL page to the relevant element. You can try setting a regular text box with the page URL:

import wixData from 'wix-data';
import wixLocation from 'wix-location'; 

$w.onReady(function () {
    let url = wixLocation.url;
    $w("#textElement").text = url;
});

Good luck,
Tal.

Hi Tall ! Thank you for your answer !
Your code was almost correct, but he .text had to be replaced by .value (I don’t know yet how to code, but I tested plenty of things and this worked)
Here is my code :

import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady(function () {
let url = wixLocation.url;
$w(“#textBox3”).value = url;
});

Indeed, do you know print only a part of the URL in this TextBox ? (Example : https://google.fr/thanks-for-helping-me-tal → /thanks-for-helping-me-tal)

$w('#idElem).text / $w('#idElem).value depends on the element :slight_smile:
As for your second query, you can check out the path function .

Good luck :slight_smile:
Tal

Hello !
I tried to use path (and all the other functions of wixLocation, but it doesn’t work anymore, even the code I wrote in my last post here !
Do you know what’s wrong ?

Thanks !
Vincent

Hi Vincent,

Can you post your code here?
path will return an empty value if you are calling it from your site’s homepage.
url should always return the full URL.

Hi Iddo !
Here is my full code :

// Pour toute la documentation API, y compris des exemples de code, visitez http://wix.to/94BuAAs

import wixData from 'wix-data';
import wixLocation from 'wix-location'; 

$w.onReady(function () {
	let url = wixLocation.url;
    $w("#textBox4").value = url;
});

Thanks !

Hi,

use $w(" #textBox4 ").value = url.toLocaleString()

Amazing, thanks for the tip !

Is there a way to send an email to a personal address with the submitted data ? This would help to create a “report” form.

Thanks

Hi Tristan,
Use this tutorial:

Good luck!
Roi

Thanks a lot Ido Inbar, it worked !
Have a nice day !

Thanks Roi, though I find it quite complicated to follow, especially since I want to use a free API like sendinblue (SendGrid not being free of charge)

Hello Tristan :slight_smile:

I created a tutorial video on SendGrid method. Link: Email Notifications with Wix Code - Wix Corvid backend Email Notification Code - YouTube

Note that I created the video in November and it still works … allows up to 100 free emails per day. (Unless you need more than that … you should be good.) See pic …

How to insert url of other page to my user input automatically and that page is dynamic page

Amazing Nayeli you’ve been of a great help ! :slight_smile:

The only thing I hope now is for the trial to be ‘forever’ as I think I saw

EDIT : I’m facing a little issue, everything works fine but the content typed in my #textBox1 is not sent, along with the label

import {sendEmail, sendEmailWithRecipient} from 'backend/email';

$w.onReady(function () {
  $w("#dataset1").onAfterSave(sendFormData);
});

function sendFormData() {
  const subject = `Notification membre : Modifications suggérées`;
  const body = `Élément à modifier : ${$w("#dropdown1").value}
    \rPseudo : ${$w("#input1").value}
    \rLien : ${$w("#input2").value}
    \rModifications suggérées : ${$w("#textBox1").value}`;
    
  //const recipient = $w("#input11").value;
 
 // sendEmailWithRecipient(subject, body, recipient)
    //.then(response => console.log(response)); 
    
  sendEmail(subject, body)
    .then(response => console.log(response));
}

I even tried copy/pasting the original line ( \rLabelHere: ${$w(“#textBox1”).value} ) it didn’t work either.

Am I missing something ?

Hello everyone,

I have made this code for a website, the objective is to have a form that stores the user’s input as well as automatically the store page url in a database.

However, it is not working, any part of it.

I appreciate any help you can give me.

Thanks.

import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady(function () {
let url = wixLocation.url;
$w(“#textelement1”).text = url.toLocaleString();

});

Hello , it works for me only on preview mode! when i go to the page online to send the form it goes wrong. Could you help me?