How Do I submit rich text to my database via the HTML comp..

Hello,

I would like users to be able to submit rich text to my database, however this is not possible with the basic tools provided by Wix, I found this :

The code works fine, but how do I set it so i can send it ty my “sample” database in the “description” field ?

Also, there would be other fields to fill in addition to this one (such as price, title, etc.) so how should I proceed so every field can send the data collected at the same time ? Thanks.

1 Like

Hi Tristan,
After you get the data from the HTML component you can use a regular “insert” function to send the data to the collection along with other fields. check out the insert API here .

Hi,

Thanks a lot for the reply, I really am not acquainted with coding, could you please give me an example code ?

Modify this code to match your needs.


import wixData from 'wix-data';

$w.onReady(function () {

  $w("myHtmlComponent").onMessage( (event) => {
    let data = event.data;
  let toInsert = {
  "text":        "data",
  "first_name":   "John",
  "last_name":    "Doe"
};

wixData.insert("myCollection", toInsert)
	.then( (results) => {
		let item = results; 
	} )
	.catch( (err) => {
		let errorMsg = err;
	} );
  } ); 
} );

I don’t understand what to replace with what.

Here is the “submit” page (works same as a forum page)


I want the rich text field to be mandatory to be able to post the data.
The orange button would submit all the data entered.

Hi Tristan,

There’s no way to connect the HTML field to a database without code, and the code is a bit complex.
Using code, you’ll need to submit the form data using button onClick .
In there, you’ll need to read the data from you input components, and the data from the HTML component. Then use wixData.insert the way or demonstrated, but for all fields.
In order to make it mandatory, check the length of the string you got back from it.

Liran.

Hmmm thanks but I’m really having hard times trying to figure out how to do it. I guess coding will never be my thing.