I’m working on a comment section for members-only pages using Memberspace as a membership platform. I’m using the following code in an HTML element to pull the member’s name from Memberspace:
First Name:
Last Name:
so that I can populate the name in a form that also includes a regular text input element:
Hi! To link the HTML text data to the same database item when submitting a form in Wix Velo, you can use the update function of the Wix Data API. This function allows you to update an existing item in a database collection with new data.
Try out:
import wixData from 'wix-data';
$w.onReady(function () {
// Bind the form submission event to a function
$w('#form').onSubmit(updateData);
});
function updateData(event) {
// Prevent the form from being submitted
event.preventDefault();
// Get the HTML text data from the form
const htmlTextData = $w('#htmlText').value;
// Get the ID of the database item that you want to update
const itemId = 'your-item-id';
// Set the new data for the database item using the setFields method
const options = {};
options.setFields({htmlText: htmlTextData});
// Update the database item with the new data
wixData.update('your-database-collection', itemId, options)
.then(() => {
console.log('Data updated successfully');
})
.catch((error) => {
console.log(error);
});
}
Thanks so much for taking the time, bamuu. I was exploring the code you provided, but I’m confused about an error I’m getting - apparently, the HTML element cannot have a field value?
Hello, if you are trying to post or retrieve a value to/from some part of the iFrame, you will want to undertand postMessage/onMessage. Please see the API documentation for all the information about what is available with this component