Submit form data to Moralis database

Hello,

I need help with the submit function to upload form data and image directly into Moralis(not IPFS). Fund my code below.


Moralis.initialize("hidden");
Moralis.serverURL = "hidden";

//File upload option in the form
connectImageUpload = async () => {
    const fileUploadControl = $("#connectFile")[0];
    if (fileUploadControl.files.length > 0) {
        const file = fileUploadControl.files[0];
        const name = "photo.jpg";

        const moralisFile = new Moralis.File(name, file);
        moralisFile.save();
    }
}


defineNewConnect = async () => {
    //Defining object class
    const NewConnect = Moralis.Object.extend("Test");
    const connect = new NewConnect();

    //Form input values from html file
    const connectNameField = document.getElementById("connectName");
    const connectDateField = document.getElementById("connectDateEditor");
    const connectCostField = document.getElementById("connectCost");
    const connectDescField = document.getElementById("connectDescEditor");
    const connectLinkField = document.getElementById("connectLink");
    const connectLimitField = document.getElementById("connectLimit");
    const connectLimitNumField = document.getElementById("connectLimitNum");

    connect.set('activityName', connectNameField);
    connect.set('activityDate', connectDateField);
    connect.set('activityCost', connectCostField);
    connect.set('activityDesc', connectDescField);
    connect.set('activityLink', connectLinkField);
    connect.set('activityLimit', connectLimitField);
    connect.set('activityLimitNum', connectLimitNumField);

    await connect.save();
}

//Need help in submit function to upload data to Moralis
submitform = async () => {
    
}

//button in html
<button id="connectSubmit" onclick="submitform()">Submit</button>

Unrelated to your ask, you may also need to add moralisFile.save();

1 Like

you can add a button and set a function to execute when you click that button

I added the onclick action to the html button already but what should go inside function here? Currently nothing is added to the database. (Updated the code in the thread just now)

you can call those 2 functions that you defined above: defineNewConnect and connectImageUpload

Getting this error.

what did you do to get that error?

Oops, should have mentioned that. Called the functions and submitted the form with data.

I mean that is the code that you added in that submitform function.

Fixed the above issue. Quick question, how do I link the User pointer in the database to the creator of this form? Sample screenshot of what it needs to look like.

1 Like

An example:

egg1 = Moralis.Object.extend("Eggs");
egg2 = new egg1()
egg2.set('user', Moralis.User.current())
egg2.save()
1 Like