How does multi insert work?

I have a situation that I can't seem ti get my head wrapped around.

I need staff to be able to select dates from a date picker for each vacation day they have left. For example, if I have 15 vacation days allowed I need to be able to select up to 15 dates. Once the desired dates are selected, I need to enter them (Each date in a new record) into the database all at once and send an email to the supervisor.

Is the multi-insert what I am looking for? Any pointers on how to use it or how I would go about accomplishing this? I just can't get my head around it.

Thanks.

Just one of many way how to solve this:

  • Create array on a front-end to save selected dates in whatever format you like
  • Send this array together with form submit
  • On back-end run a repeat and use $value to insert date

Just another way:

  • Create a form repeat to save and display (if need) selected days
  • Send this form together with your main form
  • On back-end run a repeat against this form repeat

On the server side you can just split the values (dates) sent by the $_POST by , character and repeat them using a repeat step. Put insert inside the repeat and pick the value from the repeat.

Any step by step or screenshots you can share? I didn't understand a word of that. Using the multi-insert server action shouldn't be this difficult. :frowning:

Add a repeat step
Add an insert step inside

In the repeat step select the date picker POST variable. Use the split formatter to split the POST variable value by a comma ,
Add insert step inside the repeat step.
Use the value returned by the repeat step to insert a date in the database.

Actually are you using a date picker or a date range picker?

Using the Date Picker ....

This is what I have .....

<form is="dmx-serverconnect-form" id="serverconnectform1" method="post" action="dmxConnect/api/multiinsert/multiInsert.php" dmx-generator="bootstrap5" dmx-form-type="horizontal">
                    <div id="record" is="dmx-repeat" dmx-bind:repeat="3">
                        <div class="form-group mb-1 row">
                            <label for="inp_selected_date" dmx-bind:for="insp_selected_date_{{$index}}" class="col-sm-2 col-form-label">Date</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control form-control-sm" id="inp_selected_date" name="selected_date" dmx-bind:id="inp_selected_date_{{$index}}" dmx-bind:aria-describedby="insp_selected_date_{{$index}}_help" dmx-bind:name="record[{{$index}}][selected_date]" aria-describedby="inp_selected_date_help" placeholder="Enter Selected date" is="dmx-date-picker" format="YYYY-MM-DD">
                            </div>
                        </div>
                    </div>
                    <div class="form-group mb-3 row">
                        <div class="col-sm-2">&nbsp;</div>
                        <div class="col-sm-10">
                            <button type="submit" class="btn btn-primary" dmx-bind:disabled="state.executing">Save</button>
                        </div>
                    </div>
                </form>

Screenshot 2024-11-19 at 11.29.22 AM
Screenshot 2024-11-19 at 11.29.33 AM

It inserts one record with a null value. I used the form generator to build the form if that matters.

Ah you’re using the multiple form, so you don’t need the split. Just the $_POST.record

Hmm without the split nothing gets inserted at all.

Should I change this to a bug? No records get inserted.

This old tutorial video from ancient history makes it look so easy.

https://www.dmxzone.com/go/32972/inserting-multiple-database-records/

Is the issue with date picker component only? What if you're using regular text inputs - do their values get added in the db?

1 Like

Aha! I have some progress!

Seems Date Picker breaks the multi-insert. I removed the date picker and manually entered the dates and it worked perfectly.

I will open a bug report with more details.

Yes, date picker breaks the multi insert - see above.

Particularly the difference in the network requests

There is nothing in the developer console. All clean. Gives a 200 status with and without as well. Just with the date picker no data gets inputted at all.

Request payload tab, not sure the exact name - basically where you see the form fields being sent

Sorry but this is correct?

name="selected_date"
dmx-bind:name="record[{{$index}}][selected_date]"

Thats what the form generator coded. Works fine without the date picker.

And you're using the form repeat component?
image

Don't understand why you have

<div id="record" is="dmx-repeat" dmx-bind:repeat="3">

Instead of

<div is="dmx-form-repeat" id="formRepeat1" dmx-bind:items="3">

Oh I got it now, sorry, recreated and I can see one thing:

This:

<form is="dmx-serverconnect-form" id="serverconnectform1" method="post" action="/dmxConnect/api/multiinsert/multiInsert.php" dmx-generator="bootstrap5" dmx-form-type="horizontal">
        <div id="record" is="dmx-repeat" dmx-bind:repeat="3">
            <div class="form-group mb-3 row">
                <label for="inp_selected_date" dmx-bind:for="insp_selected_date_{{$index}}" class="col-sm-2 col-form-label">Selected date</label>
                <div class="col-sm-10">
                    <input type="date" class="form-control" id="inp_selected_date" name="selected_date" dmx-bind:id="insp_selected_date_{{$index}}" 
                    dmx-bind:aria-describedby="insp_selected_date_{{$index}}_help" 
                    dmx-bind:name="record[{{$index}}][selected_date]" 
                    aria-describedby="inp_selected_date_help" placeholder="Enter Selected date">
                </div>
            </div>
        </div>
        <div class="form-group mb-3 row">
            <div class="col-sm-2">&nbsp;</div>
            <div class="col-sm-10">
                <button type="submit" class="btn btn-primary" dmx-bind:disabled="state.executing">Save</button>
            </div>
        </div>
    </form>

Goes into this:
$_POST.record.selected_date = null
But this:
$_POST.record[0].selected_date = 05/06/2009
Is this normal?

Maybe you can use a set value like this:
$_POST.record[0].selected_date+','+$_POST.record[1].selected_date+','+$_POST.record[2].selected_date
And then use the , for the repeat..

Thanks Franse, I can't use the set value as you suggested as there can be as many as 25 inputs. The number of inputs will be determined by a drop menu or text input.

I think the issue has to do with the hidden field that date picker adds. It's not being recognized.