Change the value of a form field, using VELO

Hi all,
I have been looking for a solution to this problem for some time but can’t find any solution.

I have a form for users to join the website. I would like to use this form on multiple pages, using different URLs - and to know which URL has been used by the user to register the form.

Per example, a user who filled out the form at www.website.com/page1 would then return the value “page1”
another user filling out the form on page2 would return “page2” and so on.

I believe the only way to achieve this (Without duplicating the forms) is to use VELO - as described by the WIX support team.

I would then like to know:

  1. How can I obtain the “ID” of a specific field in a form (note that I use the pre-made form tool from WIX, and NOT inputs that are connected with datasets/collections)

  2. Would anyone know how to write the VELO code to attribute a value to that field, that will be saved along with the other variables when the user fills the form.

My goal is to create a value for that field when the user loads the page or clicks submit - and I can “hide” that field so it won’t be visible to the users.

Please see screenshots on this link, which might be helpful:

Please let me know if anyone could assist with this.
Thank you for your help!

Best,
Dom

Hi Dominic

I have the same problem, Have you found any solution to this case?
I tried to create a dynamic page create my own collection and manage all things manually, but I got stuck in managing notifications and automation of submitted records

Regards,
shahin

Hi Shahin,

Yes, I found a solution; not what I wanted but a way around this.
I was using “WIX form” which I think was great - but found that it is impossible to change a value of a field using velo with this type of form.

The only solution I found was to re-create my form using the “Input fields” by pressing the “Add elements” button (Top left → add element → input)

From there, each field has a value and can be controlled independantly.
It takes a long time to re-create everything but this is the only I found.

Once this is done, to change and save the fields values can be done from the velo code panel.

Here’s an example of my code - which I hope can help you:

//Connect the databases for the functions below to work
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’

//Create the variables waiting for their values to be assigned
var titleVariable;
var itemObj;
var investorRequestsData;

//Function that get activated when the page loads. In my case, the variable “#referralinput” field will have the value of the referrer that I assigned in my dataset. (Btw you can then HIDE that field if you want it to show)
$w.onReady(function () {
let itemObj = $w(“#dynamicReferrersDataset”).getCurrentItem();
let titleVariable = itemObj.title; //get the relevant field key
$w(“#referralInput”).value = titleVariable;

//Action when the user click on the form button (Make sure the button name is #submitBtn
$w(“#submitBtn”).onClick(() => { submitForm(); });
});

//Function for when the user press the submit form
function submitForm() {
//All variables get assign the value that are in the fields
let investorRequestsData = {
name: $w(“#nameInput”).value,
email: $w(“#emailInput”).value,
referral: $w(“#referralInput”).value,
phoneNumber : $w(“#phoneNumberInput”).value,
countryOfResidence : $w(“#countryOfResidenceInput”).value,
linkedInUrl : $w(“#linkedInUrlInput”).value,
describes : $w(“#discribesInput”).value
};
//All the variables are assigned to the dataset
wixData.insert(‘InvestorRequests’, investorRequestsData);
//Once the above is done, the user gets redirected to another page that confirm the form has been received correctly
wixLocation.to(“/investor-detailed-information”);
};


I hope this helps you. I looked for a solution for weeks and even WIX team couldn’t understand what I was trying to achieve. But long story short - velo does not work with WIX form and everything had to be re-done using the fields input.

Let me know if I can help you further.

Thanks,
Dom

Thank you Doninic

It’s a great workaround, I try and find Wix form input elements “key” as you say,
but I have a question. you use another collection to save submitted data or in this line:

wixData.insert(‘InvestorRequests’, investorRequestsData);
‘InvestorRequests’ is your Wix form name or your collection name? it should be the collection id
i have a problem here, and can’t manage or find my wix forms collection id

best,
shahin

Hi Shahin,

Yes - the “investorRequests” is my collection name.
I know the problem you have. I had the same issue finding the correct name to place in my velo code.

I might be wrong - but I think if you go to your DNS - and look at your collection name, at the right there will be 3x dots to have more options. If you look at settings, you can see your Collection name there. I believe this is the one you need to place in your Velo code.

Also make sure that the permissions & privacy are updated.
Again, I am no expert but I put mine to “Anyone can view,add and update content” just to be sure.

This worked for me. Can you try this and see if this work?

Thank you again

I’m new in Wix, it’s so good this conversation to me,
I’m trying to find a solution to it, I can’t use Wix Forms, because of doesn’t support multilanguage and otherwise, I want to use the automation and mobile app facilities of Wix Forms