Collect dynamic page ID from User Input Form Submission

I’ve created an Association website, which displays individual association members (in the screenshot attached, “Solution-providers”) on their own dynamic page.

I need visitors to be able to ask for an introduction to a particular member (“enquire”), so I’ve created an “enquire” email form on the dynamic page template.

I’ve successfully set up and tested the user input database (“Partner-intro-enquiry”), in that it collects the email of the visitor.

BUT I can’t see how to also collect the relevant member’s ID on “submit”, so that the visitor database shows which specific member they enquired about.

I’m not a coder, so while I’ve trawled Wix support looking for an answer, I haven’t been able to figure out a solution. Any help would be awesome!

1 Like

Hey Dan!
Put your id on a text box and then just add the following line:

 $w('#dataset1').setFieldValue('fieldname1', $w('#textbox1').text); 

what this code does is that it takes the text on your textbox1 and puts it on desired field of the desired dataset so whenever someone submits a data through your form, this information will also be added on to the related field.
If that id is also that page you are on you can also use wixLocation.url or wixLocation.path instead of $w('#textbox1).text
You can learn more about wixLocation here

Hey Mert, thanks for your reply. I tried the code exactly as you provided (updated, obviously, with my data/field info — e.g. #textbox1 became #text35), and it didn’t work.

Since the text in #text35 is dynamic I wondered if that was the problem with this approach, so I also tried the wixLocation.path option, just to see if that worked. Still no luck. In case I did something wrong, I’ve attached a screen shot – can you see any issues?

Hey Dan,

A couple things…

  1. If the dynamic page is by member ID, then you can get the ID this way:
import wixLocation from 'wix-location';
...
let id = wixLocation.path[1]; // retrieve second item

wixLocation.path returns an array of the dynamic page prefix and value. In my code, I retrieve the second item which is the value (ID).

  1. Use the onReady() function of the dataset to ensure that the dataset is ready.

Finally, you can set the dataset’s field:

$w("#dataset2").onReady( () => {
    $w('#dataset2').setFieldValue('partner', wixLocation.path[1]); 
} );

I hope this helps. Let me know how it goes.

Yisrael

Hey Yisrael, thanks — but nope. Still not working. Screenshots attached, both of the page with the code showing, and the dataset showing that it’s collected my email, but not the partner/page info — just in case that tells you anything…

Incidentally, not certain what you mean by “by member ID” but at this stage we don’t have a “member section” as such, or member-generated content, though that’s in the long term plan. Right now it’s just us as admins trying to get the site working properly between the databases and the live front end (what I mean is: right now there’s no “literal” member ID, though effectively each member has an ID given that they’re in a dataset called “Solution-providers”; the Title field (or ID) of which is what we’re trying to collect.

In case this also helps: I had other code on the page, which I’ve removed to eliminate variables. Here are screenshots showing the code (copied straight from you, @Yisrael) , and the error message I’m getting on Preview:

The code I showed you needs to be inside the page’s onReady() function.

$w.onReady(function () {
   //TODO: write your page related code here...
   $w("#dataset2").onReady( () => {
       $w('#dataset2').setFieldValue('partner', wixLocation.path[1]); 
   } );
   //TODO: write more page related code here...
});