How to send HTML element text to database for Memberspace integration?

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:

My simple question is how to link the HTML text data to the same database item when submitting the form. I’ve tried some code for the “insert” function provided in a previous post (https://www.wix.com/velo/forum/coding-with-velo/how-do-i-submit-rich-text-to-my-database-via-the-html-comp) but wasn’t able to get it to work.

I would appreciate any input!

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

And here is an article explaning how to use the iframe element that may help with the concept.

I was wondering about postMessage/onMessage but wasn’t sure if it was the right direction to go - thank you for your post.

I modified the example in the iFrame document and it works!

Yay! Happy to hear it’s working for you. Feel free to start a new post if you run into any mroe problems