Now I want to create dynamic Check box fields in the form that look like this –
<div class="form-check">
<input class="form-check-input" type="checkbox" value="1" id="inp_int_event" name="int_event1">
<label class="form-check-label col-form-label" for="inp_int_event1" id="training1">Name of Event Training 1</label>
</div>
I want these to be generated dynamically, too. The menu list is connected to a table with multiple records – a different event and its details in each row.
If a new event row is added to this table in the back end then the list of 7 checkboxed options should dynamically result in 8 checkboxed options.
This is a PHP to mysql project. In PHP I’ve created dynamic lists linked to a table but what are the Wappler components and steps to convert the Dynamic Select Menu into a checkbox list like this?
So I have to modify the dynamic list checkbox I have now so that the name is dynamically generated for each output checkbox field -- which I suppose is "int_event"+
I've tried something like this -- it doesn't produce errors but I doubt I have done this correctly
Yes. 7 fields because this is not a check box group say, saved to an array held in one field.
Client wants to see multiple submissions from the same user over time where Separate events have their own field or column if it is an Excel sheet.
At any rate — and each checkbox sends the event id number into a field devoted to the history of registrations to that event.
On submission Event 1 when clicked sends value 1 to event_id1
On submission Event 2 when clicked sends value 2 to event_id2
On submission Event 3 when clicked sends value 3 to event_id3
On submission Event 4 when clicked sends value 4 to event_id4
As my query image shows.
The dynamic query code I now have looks like this in my form –
The unique field id is just a number 1 or 2 or 3 which I wanted to use to append to the input name=“event_id”+" in effect –
which is what I was trying with:
name="int_event.trainings.data.query[0].int_events" hoping that it would write out name=“event_id1”
and next dynanic row would read – name=“event_id2” etc etc
because
each eents table record starts with event_id = 1
event_id = 2
event_id = 3
and now with 4 records of events –
event_id =4
But when I check the output on submit in
Developer Tools it shows one dynamic check box input all with same value= “1”
The dynamic labels are working so it is stepping through the table
Are your checkboxes always going to be 7 and exactly 7? (yes / no) NO
If the answer to previous question is yes - do you want to store each checkbox value in a separate database column? In 2022 the client expects have no more than 6 events. I added one spare field the 7th record.
IF the Events table expands to 6 events then the purpose of the dynamic query I've spent this day on is to immediately output a form online that now has the same number of checkboxes with the appropriate title, etc. And dynamically the sequence of value for each checkbox ascends from 1 to 6,
And, yes, six different fields will be waiting in the register event table for each checkbox result.
If the answer is no - how do you want to handle the values if the checkboxes are not exactly 7?
Due to the peculiarity of the client & the fact that they want simple to read Excel sheets generated every week to track who is registering and what events they've added on multiple visits to the form this is the way it is, for now.
I just want something like this generated DYNAMICALLY
I’ve done this for over 12 years, If the client goes into the dashboard and adds a couple more events then immediately the user logging in to register now sees new checkboxes with a description for each.
The value output is just an inteeger, not a varchar.
For this client I always have a few extra fields waiting in the database table when they change their minds later and I have to be flexible.
Doing it this way the client can get a simple Excel export from the app online and can more easily follow the columnns, with the numbers always visually reminding them that a value of 3 means the 3rd event. Blah blah…
And which part is challenging for you exactly?
I posted you an example how to create dynamic checkboxes. Then you started with some long posts which i really have hard time understanding. Try shorter and clearer questions please.
Yes, they were long responses.
Describing precisely the problem.
The name of the field and its value have to also iterate with each repeating loop.
The method which I appreciated and thanked you for does not quite achieve this
The only difference in the successive checkboxes created dynamically is the LABEL
I need each NAME to match the database field (which changes from int_event1 to int_event2, etc, and VALUE for each has to match the number fetched from the key field.
Changing @Teodor 's suggested code worked like this for me –
In the browser each input is dynamically produced from the contents of the online “trainings” table –
The id and name are alike but most importantly the name=" " matches the relevant field it is to be saved in to at the “trainingsform” table.
I substituted a dynamic query variable “int_events” for $index (which gave me ascending numbers 01, 11, 21, 31, 41 – wouldn’t work) to get single digits 1,2,3,4,5 while providing the appropriate Value= and Name=“event_id1” until it reached checkbox input name=“event_id5”.