You can work with Forms using Velo APIs in 2 different ways:
Let's present each approach so you can decide which to use.
Wix Forms is an app solution that provides you with a built-in suite of form functionalities, such as an out-of-the-box submission button, database collection creation, and auto-generated emails after submission.
First use the Wix Forms app to set up your forms quickly and efficiently, taking advantage of Wix Forms features. You even get a starter collection for your form that you can use to store the form data.
Then use the WixForms Velo APIs to customize the visitor experience even more. For example, you can display a personalized thank you message when a visitor submits the form.
Check out the benefits of the Wix Forms app!
Using Wix Forms Starter Collections
When you add the Wix Forms app to your site, you pick the type of form you want. Depending on the form you pick, you get a collection specifically built for that form. In addition to the form appearing in the Form Submissions tab in the Dashboard's Customer Management area, you can also see the collection in the Database section of the Velo Sidebar.
We call these collections starter collections because that's exactly what they are for, to help you get started. You can use the collection "as is" or you can change the collection to meet your needs. For example, when we add a Donations form to our site, we get a starter collection called Donors with basic fields. Here we customized the collection by adding a Signature field.
The fields on the Donations form are connected to the fields in the Donors collection. This means that each time a visitor submits a form, the form field data is stored in the corresponding field in the collection.
The opposite is not true. Adding a field to a starter collection does not add a corresponding field to the form.
Using the WixForms API
$w("#wixForms1").onWixFormSubmitted( {fields} => {
let firstName = fields[0].fieldValue;
let lastName = fields[1].fieldValue;
let donation = fields[2].fieldValue;
let email = fields[3].fieldValue;
$w('#text1').text = `Thank you, ${firstName} ${lastName}, for your generous donation of ${donation}.`;
});
/* fields array of objects:
* [
* {
* "id":"inputFirstName",
* "fieldValue":"Maria",
* "fieldName":"Enter first name"
* }
* {
* "id":"inputLastName",
* "fieldValue":"Santora",
* "fieldName":"Enter last name"
* },
* {
* "id":"inputDonation",
* "fieldValue":"1000",
* "fieldName":"Enter donation amount"
* },
* {
* "id":"inputEmail",
* "fieldValue":"ms@theCompany",
"fieldName":"Enter email"
* }
* ]
*/
To provide your site visitors with a fully customized form experience that you totally control, you can create custom forms manually. Add user input elements and buttons to the page, and code their usage to act like a form.
Using Velo APIs to create your own custom forms may take a bit more time and coding than using the Wix Forms app, but customizing your own forms can offer some advantages, such as enabling additional field types and using advanced functionality with code, without adding Ascend to your site.
Using APIs for Custom Forms
Here are some examples and tutorial articles to help you get started.
Tutorial Articles
Examples
Previously published at https://support.wix.com/en/article/velo-working-with-forms