Import from form - Repeat Children

Hello!

I’m followed the tutorial for shopping cart using Data Store and all is working fine, except the check out part, where I need to record to the database the data from data store.

Below, my checkout page, where I show the cart content, complementary fields and a hidden repeat with the data from my shopping cart:

Now, I would like to insert a “order” to my database table + order details (cart data).
Before create all all the steps, I need to define my posts variables, importing from the checkout form, but the “repeat” doesn’t import as an array and I can’t use Multi-Insert Query:

What am I missing?

Thanks!

Have a look at

1 Like

Thanks Ben! I made a lot of validations using the Data Store already, change everything to local storage + arrays at this time of my project is a not a good idea :frowning:

What I’m trying to do is wrong? Data Store is an array too, right?
I just tried to convert the data store to an array (flow) and using the array in the repeat, but the problem remains the same…

@George any tip?

anybody?

Your hidden inputs need to have a name binded to them. For example in your situation your product_id field should be something like:

<input type="hidden" id="product_id" dmx-bind:value="product_id" dmx-bind:name="record[{{$index}}][product_id]" name="product_id">

If all your hidden inputs are like this then you will see the array in your post variables.

2 Likes

WOW! Thanks Max!!
Now, the repeater is imported as an array! Thanks!
But, now, the fields are returning: object object

INSERT INTO order_detail (order_id, product_id, product_name, quantity, unit_price) VALUES (‘48’, ‘[object Object]’, ‘[object Object]’, ‘[object Object]’, NULL)

:frowning:

Have you checked that these hidden inputs have different id’s to any other form fields on your page?

1 Like

OMG! You nailled it!!

Many thanks, Max!! It is all working now!

1 Like

This solution also worked for me, although I wonder that this has to be entered as code and shows in the Dynamic Attributes list like this:

image

Anyways, it seems I set it right, because the repeater’s record is available as an array in the POST variables now:

image

However in the “Database Insert Options” I can’t select the array’s fields like product_id:

image

So I tried inserting the data with these manually added values:

image

What am I doing wrong?

Yes this does need to be entered in code view instead of the properties panel.

You will need to run your Database Insert step inside of a repeat too and set this as your record array.

Still having trouble with this, hoping anyone can help.

I got the Database insert repeated to create the order records/order lines into the order_records database table, like here:

Then these order lines are added to the orders table in the order_lines field (which is of the Reference field type):

Also the customer (which is created in the insert_customer step is added to this table to the customer field, which is also of the Reference type.

For some reason which I can’t point out, the customer and order_lines data stay empty and are not inserted. Anyone a suggestion what might be the cause of this?

Thanks in advance for any help.

This issue is clearly Reference field related, as I also posted here. Anyone else having these problems with reference fields or is it just me?