Update Data Collection From Text Field

Hello Everyone,

Hopefully, this should be my last step in website coding, and I’m stuck.

I’ve created a multi-step booking form using slideshow on a dynamic page.
On slide1: some info is entered by the user
On slide2: other infos are entered.

On Slide 3: It’s a kind of Review page, where the user can review all the entries he entered AND some of the info that we’re brought in from the dynamic page being connected to a dataset.

After reviewing, he can confirm and submit the info by clicking a button.

So basically, the last slide is a bunch of texts returning the data he entered in the user input field, and some texts returning some info from the dynamic page.

Is there a way to connect the #texts return on the last slide to my form submission dataset (not the #input fields themselves)?

When I tried to connect the text elements to fields in the data collection, and click submit button, it shows empty (probably because the submit button only takes the data from the input element and not the text element)

If you’re asking if you can do it without code, I don’t know.
But you can do it with code.

import wixData from 'wix-data';
let toInset = {};
$w.onReady(() => {
    $w("#submitbutton").onClick(event => {
        toInsert.name = $w("#input1").value;
        toInsert.additioanInfo = $w("#text1").text;
        //etc...
        wixData.insert("CollectionName", toInsert)
        .then(() => {/*show message*/})
    })
})

Somthing like that

Hey J D,

Thanks for the reply,

I’m not quiet sure I understand that coding. Let me tell you what i understand from it.

toInsert is telling the code to write the text or input into a field called name (so if the field in the collection is for example firstname, it would be toInsert.firstname, right)

and then the wixData.insert, tells it to insert these saved inserts in this collection name.

but what’s the .then(() => {/show message/}? do you mean like a success or failure message? what if I want to direct it to a thank you pgae, instead of showing a message?

Thank you

@towayer

  1. toInsert is the data object you’re going to insert. This object’s properties are your collection field keys. So yes - toInsert.firstname defines the value for the firstname field.
  2. wixData.insert is the insert command.
  3. Yes, it’s the success message. If you want to redircet the user then:
import wixLocation from 'wix-location';//this line should be at the top of your page code.
//code...code...
.then(() =>  wixLocation.to("/successpage")); //use the page path
//code...

@jonatandor35 Thank you very much for the clarification, I’m giving it a try now. hope it works

@towayer You’re welcome. I modified the code, so make sure you’re using the last one.

@jonatandor35 Like a charm… Thank you so much for your help. Finally done with all my website coding.

@towayer You’re welcome :slight_smile: