I built a multistep form of 14 'pages' (steps), on one step (10) we ask for an address, on step 12 we ask for the number of years att he current residence. If this number is less than 5 years, I have to add another address, as long as the total number of years is 5 or more years total. So, it can be any number of addresses untill step 12 equals 5+.
To be quite honest I have thought of how to do this, but I really am stuck.
The number of years + months from step 12 are just saved in the form until the end when they are submitted. They are not saved as subtotals, nor as form-group arrays.
Tabs/Steps are as follows
...
<!-- Step 10 -->
<div class="tab-pane" id="wizard-validation2-step10" role="tabpanel">
<?php
include_once 'assets/steps/step10.php';
?>
</div>
<!-- END Step 10 -->
...
<!-- Step 12 -->
<div class="tab-pane" id="wizard-validation2-step12" role="tabpanel">
<?php
include_once 'assets/steps/step12.php';
?>
</div>
<!-- END Step 12 -->
...
The PHP includes are just form fields, like:
<div class="form-group">
<div class="input-group">
<input type="number" placeholder="0" class="form-control input_number" id="durationyears" name="durationyears" min="2" required>
<div class="input-group-append">
<span class="input-group-text input_number">
Years
</span>
</div>
</div>
</div>
I'm using this Github project (thanks VinceG): https://github.com/VinceG/twitter-bootstrap-wizard
When the total number of years in too low, I could go back to step 10 with this:
$('#rootwizard').bootstrapWizard('show', 'wizard-validation2-step10');
clear the current fields and add a new address somehow.
I'd love to know how I can get the address from step 10 as a new, additional n-th address and the number of years from step 12 as a new value as well.
It should then look like something like this when $_POSTed:
address[0] = addressstreet
address[0] = numberofyears
address[1] = address
address[1] = numberofyears
total numberofyears = address[1][numberofyears] + address[1][numberofyears]
I'm hoping somebody can put me in the right direction. It's late, been a long day so I hope this made sense. Stay safe & healthy everybody!
EDIT:
I now have more detailed info which helps clarify things. What I need is this structure
"Addresses": [{
"Building": "The Granary",
"BuildingNumber": "2",
"SubBuildingName": "Flat 1",
"Postcode": "FA11 0UT",
"Street": "Street",
"Town": "Megaton",
"County": "Maryland",
"TimeAtAddressYears": "13",
"TimeAtAddressMonths": "10",
"ResidentialStatus": "Living With Family"
}, {
"Building": "101",
"Postcode": "FA11 0UT",
"Street": "Vault lane",
"Town": "town",
"County": "Maryland",
"TimeAtAddressYears": "5",
"TimeAtAddressMonths": null,
"ResidentialStatus": "Tenant - Private"
}],
TimeAtAddressYears must be at least 5 for all Addresses combined. Can be 1 address, can be 5 (maybe more if we start using the months as a leading time, so 60 months where 1 year will be 12 months obviously.
So, the step where I ask for the TimeAtAddress is Step 12. I need to check with jQuery if th etotal submitted value there is >5 before going to the next step, or go back to Step 10.
I'm thinking of creating/appending hidden fields for this and write a new address to these hidden fields, sort of like this form input field sample for each of the values needed. "n" is the number of $i and will be increased after each check:
<input type="text" name="Addresses_Street" id="line1">
^ will save to the hidden field below for later processing
<input type="hidden" name="Addresses[n][Street]" id="Addresses_n_Street">
So, now I am a step further, still need to know this now:
- check the total values of
Addresses[n][mc_residential_durationYears] to be >5
- go back to Step 10 when needed, where I can ADD TO new Address fields
$i++ (=n) <input type="text" name="Addresses_Street" id="line1"> will get new address and save to the hidden field below for later processing <input type="hidden" name="Addresses[n][Street]" id="Addresses_n_Street">
I'm seeing this as a solution, just have to get it all written out. Is this a good way to go or is there a better (right) way to go?