Repeat Selection and Insert Multiple Records Solution
I have a section of a form that gives information on Flat / Apartment blocks if there is more than one block. There is an input field that firstly asks how many blocks at the property. This value can be between 2 and 8.
<input type="number" class="form-control" id="blocks" name="blocks”>
I would like to use this value as the dynamic value for a repeat selection below it. The repeat selection will have two input fields repeated: 'Block name' and 'Block Numbering'. So for example if the input field above has the number 4. The two fields in the repeat selection will be repeated 4 times.
See attached screen shot to see how it looks using a static value of 8 for the repetitions ( 8 is the maximum accepted )
<div role="group" class="row block-details" area-labelledby="block-label">
<?php
// RepeatSelectionCounter_1 Begin Loop
$RepeatSelectionCounter_1_IterationsRemaining = $RepeatSelectionCounter_1_Iterations;
while($RepeatSelectionCounter_1_IterationsRemaining--){
if($RepeatSelectionCounterBasedLooping_1 || $row_None){
?>
<div class="col-md-6">
<div class="form-group row">
<label for="blockName1" id="block1-label" class="sr-only">Block 1 name</label>
<div class="col-lg-6 col-xl-7">
<input class="form-control name" name="block_name_1" id="blockName1" placeholder="Name of block 1" >
</div>
<label for="blockNumbering1" id="numbering1-label" class="sr-only">Block 1 numbering</label>
<div class="col-lg-6 col-xl-5">
<input type="text" class="form-control" name="block_numbering_1" id="blockNumbering1" placeholder="block 1 Numbering i.e 1-9'" required="" >
</div>
</div>
</div>
<?php
} // RepeatSelectionCounter_1 Begin Alternate Content
else{
?>
<?php } // RepeatSelectionCounter_1 End Alternate Content
if(!$RepeatSelectionCounterBasedLooping_1 && $RepeatSelectionCounter_1_IterationsRemaining != 0){
if(!$row_None && $RepeatSelectionCounter_1_Iterations == -1){$RepeatSelectionCounter_1_IterationsRemaining = 0;}
$row_None = mysql_fetch_assoc($None);
}
?>
<?php
$RepeatSelectionCounter_1++;
} // RepeatSelectionCounter_1 End Loop
?>
</div>
My problem is when I change the ‘repetitions value to a dynamic value using the ‘blocks’ input’ .. It doesn’t work.
<?php
// RepeatSelectionCounter_1 Initialization
$RepeatSelectionCounter_1 = 0;
$RepeatSelectionCounterBasedLooping_1 = true;
$RepeatSelectionCounter_1_Iterations = "".((isset($_POST["blocks"]))?$_POST["blocks"]:"") ."";
?>
What’s wrong here?
Plus is it possible to create placeholders dynamically so they are numbered correctly for the amount of repeats.
(Page attached)
Thanks in advance!