onBeforeSave and custom form

I am working with a client and need to save some extra information alongside the custom form that they are using.

I have been following a tutorial on how to do this and have hit 2 problems.

Firstly, the text box that I am using to show the validation message doesn’t show.

Secondly, I don’t know where to add the onBeforeSave function to save the additional information.

Here’s the code:

import wixData from 'wix-data';

$w.onReady(function () {

});

function validation() {
    let validationMessage = "";
    if ($w("#input2").valid && $w("#input3").valid) {
        saveProperties(); {
        }       
    } else {

        if (!$w("#input2").valid) {
            validationMessage += "Please enter a Business Name.\n"
        }

        if (!$w("#input3").valid) {
            validationMessage += "Please enter a Business Name.\n"
        }

        $w("#textErr").text = validationMessage
        $w("#textErr").show().then(() => {
            $w("#input2, #input3").updateValidityIndication()
        })
    }
}

function saveProperties() {
    $w('#buttonSubmit').disable()

    let toInsert = {
        "businessName": $w("#input2").value,
        "businessEmail": $w("#input3").value,
    };

    wixData.insert("Properties", toInsert)
    .then ((results) => {
        let item = results;
        console.log(item);
        $w("#textErr").text = "Your information has been submitted"
        $w("#textErr").show().then(() => {
            clearAllElements()
            $w("#buttonSubmit").enable()
            setTimeout(() => {
                $w("#textErr").hide()
            }, 5000
            )
        })
    })
    .catch((err) => {
        let errorMsg = err;
        console.log(errorMsg)
    });
}

function clearAllElements() {
    $w('#input2').value = null;
    $w('#input2').resetValidityIndication();
}

export function buttonSubmit_click(event) {
    validation()
}

I’ve got the validation message working. There was some extra code that was causing some problems. Now just the onBeforeSave

Hi there :wave:t2: The onBeforeSave will be added as a data hook, you can check out how to set it up here:
https://support.wix.com/en/article/velo-using-data-hooks

Good luck!

Awesome! Thanks for the help. I found another way of submitting the data that I needed to by adding it to the let to insert section.

This form allows users to submit information to database to be displayed on dynamic pages on the site. I’m kinda struggling to understand how I allow them to update this information that they have submitted, without it creating another entry. Would it be possible to be pointed in the right direction?