How to prefill/ autofill a section of a form from a button

I have 3 contact pages corresponding to 3 buttons that are linked to each contact page, each contact page is for a different service. I am wondering how I can autofill/ prefill a section in the form so that when someone clicks the button to go to one of the 3 contact pages the service section of the form is already filled out.

1 Like

If you want to load data into a form, the data must be stored somewhere.

Where is stored your contact-data?
When you talk about “contact-pages”, what is in your project a “contact-page”?
Is it a dynamic page? If so, then you surely will have a database, right?

When you ask questions, please always try to describe your situation as most detailed as possible, then you will also get better and faster answers.

More INPUT = more OUTPUT.

Your situation:

  1. Click on a button
  2. load data out of DB
  3. put data into form

Your way to glory…

  1. Starting your custom function by a click onto your button…
$w.onReady(()=>{
	$w('#myButton').onClick(()=>{
		myFunction();
	});
});
  1. Getting data out of DB (dynamic dataset)…
    getCurrentItem - Velo API Reference - Wix.com
$w.onReady(()=>{
   $w("#myDataset").onReady(() => {
       $w('#myButton').onClick(()=>{
           myFunction();
       });
   });
});

function myFunction() {
   let itemObj = $w('#myDataset').getCurrentItem();
   let itemID = itemObj._id
   let itemOWNER = itemObj._owner
   let itemTitle = itemObj.title
   console.log(itemObj)
   console.log(itemID)
   console.log(itemOWNER)
   console.log(itemTitle)
}

Take a look onto console. What do you get?

  1. After you have got your data out of DB now you want to put it into your form?
    Expand the function…
function myFunction() {
   let itemObj = $w('#myDataset').getCurrentItem();
   let itemID = itemObj._id
   let itemOWNER = itemObj._owner
   let itemTitle = itemObj.title
   console.log(itemObj)
   console.log(itemID)
   console.log(itemOWNER)
   console.log(itemTitle)
   
   $w('#myTextFieldElement1').text = itemID
   $w('#myTextFieldElement2').text = itemOWNER
   $w('#myTextFieldElement3').text = itemTitle
}

sorry, Ill try to be a bit more descriptive, so I have a services pace (1st picture) which has 3 buttons, those 3 buttons are linked to 3 identical pages (but not the same page) within my site. I have a standard wix form for all 3 contact pages that allows people to contact me about the service that they clicked on, (picture 2 is one of the 3 contact pages) I want to know if there is a way I can grab data from the button that they clicked on the services page(1st Picture) and transfer that to the corresponding service page and autofill the “Service of Interest” section of the form to whichever service that they clicked on. for example, if they clicked on the automotive services I don’t want them to be able to write in a different service on the form that is dedicated for automobiles I want it to prefill the “Service of interest” section to Automotive they can edit any other box just not the service of interest one. I hope this helps! thank you for replying so fast!

@lddevore041
I will take a second look onto your issue the next days. Stay tuned…

I took a second look onto your issue. Since you use Wix-Forms, normaly you should find your answer here…
https://www.wix.com/velo/reference/wix-crm/$w-wixforms