Autofilling a form without membership - using contact info

Question:
How to take a user inputted email and return their data from their contact information and auto fill the rest of the relevant fields?

Product:
wix Editor

What are you trying to achieve:
I have a form in which I want the client to fill in their email address. Then there are 3-9 fields that will autofill based on a previous form that was filled out. I am not using members as the person is not a member yet.

What have you already tried:
I have a backend code that seems to be finding the correct collection, and it is looking for the correct email field. The collection name and field name all match in the code. I would rather not have to do this with a collection, but have tried other ways and it has not seemed to work either.

I have the code I have been using but every time I include it the AI flags it and it never gets approved.

If the form is already submitted, you would query it from the database (if it’s a wix form you would need to use a different query method otherwise, if it’s a cms form then the below will work). Here’s a quick example:

import wixData from 'wix-data';

$w.onReady(function () {
    autoPopulateFields()
});

async function autoPopulateFields() {
    const data = await getUserByEmail()
    const item0 = data[0] // only returns 1 item so we just need the first
    if (item0) {
        // do this line for each field you need updated
        $w('#fieldToUpdate').value = item0.yourFieldKey // if need a string, you can use .toString() or .toLocaleString() or `${item0.yourFieldKey}
    } else {
        // do an error handling or some kind of message
        return {error: 'No user found by this email'}
    }
}

async function getUserByEmail() {
    let query = await wixData.query('YOUR COLLECTION NAME').eq('email', $w('#email').value).limit(1).find()
    return query.items
}```

Thanks. this looks very similar to my code:

import wixData from 'wix-data';

$w.onReady(function () {

    const myCollection = "AllContacts";  // the name of my collection - It is not on the webpage though.

    const search = () => {
        let query = $w("#emailInput").value;
        console.log("what email am I looking for? ", query);
        wixData.query(myCollection)
            .contains("email", query)
            .find()             // this aways returns a null, or array 0
            .then((results) => {
                console.log(results.items);
            })
            .catch((error) => {
                console.log(error);
            })

    }
    $w("#emailInput").onBlur(search);
})

The problem is that it returns the inputted email, but when it searches for the email in the collection it returns null.

this is an image of my collection.

In case you need it. This is the form and the console messages.

Ideally I would like to skip using the collections, but I have not been able to get the connection to the Wix Contacts to work correctly.