How to get title from dynamic page after form submission?

Hi!!

I have a dynamic page in my site in which there are forms a user can submit. Is there a way in which i can know exactly from which site a given user typed/filled the form?

Thanks in advance!!

Are you refering to getCurrentItem

#dynamicDataset - dynamic Dataset

$w.onReady( () => {
 $w("#dynamicDataset").onReady( () => {
    let currentItem = $w("#dynamicDataset").getCurrentItem().title;

  } );

} );

This might help -

import wixLocation from'wix-location';

export function submit_onClick(events){
    let prefix = wixLocation.prefix;
    let path = wixLocation.path;
    
    $w("#collectionName").setFieldValue("path" , path);
    $w("#collectionName").setFieldValue("prefix" , prefix);
}

To know more about the path and the prefix visit here.
Also when you will be using the path you must have some knowledge about arrays.

Hi, Rinshul! Thanks for your help!

I’m a Wix Code rookie -to say the least- so i’m still struggling a bit to catch up on some things, so apologies if i make dumb questions :pensive:.

Should i create a new field in my collection called path and another one named prefix?

Also, the form is located within a lightbox, so should i add a dataset to the lightbox?

Also, where can i see, after putting the code from which site the user submitted the form?

Thanks for all your help, Man!

@jpsanchez0514

  1. Should I create a new field in my collection called path and another one named prefix?

Ans : Yes (It is your wish that your work will be done with prefix or path or you might need both )

  1. Also, the form is located within a lightbox, so should I add a dataset to the lightbox?

Ans : No, there is no such need but add this code only to the onClick function of submit button

  1. Also, where can I see, after putting the code from which site the user submitted the form?

Ans : It will be displayed in your collection .

I hope it will help!!

@rinshulgoel Hey man!

Thanks for all your help. I really appreciate it!

I’m trying to do it, but when putting the code on the lightbox, i get a message saying “Not a valid selector” in line 5 & 6 ($w ( “#collectionName” ). setFieldValue ( “path” , path ):wink:

I’m using the form’s collection ID defined on my site, but no luck… What should i do? :sleepy:

@jpsanchez0514 I think you should not use the collection name/id
instead use that of dataset’s
https://support.wix.com/en/article/adding-and-setting-up-a-dataset

Hi! I finally found a solution that worked for me…

Thanks to @rinshulgoel for the base code.

Here are a few things to note:

  • Indeed, as @ajithkrr says, it is the Dataset’s ID that should be used. Not the Collection ID.

  • The Dataset must be in Write Only mode.

  • I had to add a .save command, so both the prefix and the path were succesfully saved to the collection.

This is what my final code looked like:

import wixLocation from ‘wix-location’ ;

export function submit_onClick(events){
let path = wixLocation.path;
let prefix = wixLocation.prefix;

$w( "#dataset1" ).setFieldValue( "path" , path); 
$w( "#dataset1" ).setFieldValue( "prefix" , prefix); 
$w( "#dataset1" ).save(); 

}

Thanks everyone for helping out!!