WixData Insert not inserting field values from input box

I am trying to write data on my CMS collection using wixData insert, on a Lightbox. However, two of the fields come from a dynamic page - placed that on text5 and text6. Using the insert function on a button, only the two variables are written to the collection’s field and the other input (from input1) is blank.

import {lightbox} from 'wix-window-frontend';
import wixWindowFrontend from 'wix-window-frontend';
import wixData from 'wix-data';

let receivedData = lightbox.getContext();
$w('#text5').text = receivedData.presemail;
$w('#text6').text = receivedData.presname;

$w.onReady(function () {
	
	
	$w('#text8').text = receivedData.title;
		
	let toInsert = {
		"title": $w('#input1').value,
		"recepientEmail": $w('#text5').text,
		"recepientName": $w('#text6').text
		};
	let options = {
  		"suppressAuth": true,
  		"suppressHooks": true
	};

		function insertdata() {
		if (wixWindowFrontend.rendering.env === "browser") {
			return wixData.insert("RFPs", toInsert, options)
			.catch( (err) => {
             console.log(err);}
			)}}

	$w('#button9').onClick(insertdata);

});

Any help is greatly appreciated.

try this

import {lightbox} from 'wix-window-frontend';
import wixWindowFrontend from 'wix-window-frontend';
import wixData from 'wix-data';

let receivedData = lightbox.getContext();
$w('#text5').text = receivedData.presemail;
$w('#text6').text = receivedData.presname;

$w.onReady(function () {
    
    $w('#text8').text = receivedData.title;
        
    let options = {
          "suppressAuth": true,
          "suppressHooks": true
    };

    function insertdata() {
        let toInsert = {
            "title": $w('#input1').value,
            "recepientEmail": $w('#text5').text,
            "recepientName": $w('#text6').text
        };
        if (wixWindowFrontend.rendering.env === "browser") {
            return wixData.insert("RFPs", toInsert, options)
            .catch( (err) => {
             console.log(err);}
            )}

    $w('#button9').onClick(insertdata);

});
1 Like

Thank you. It worked.

I was following Wix’s page rendering process so I got it mixed up with the data to insert before the page loads.

Thanks again!

2 Likes