I have a client that is a financial advisor and he tasked me with implementing an income calculator for his business clients.
The values for calculating the outcome change, depending on a tax year, but the formula to calculate it is always the same.
So the first form field needs to be year and based on the chosen year, the (hidden) fileds containing the specific values to calculate the outcome would need to be populated.
I was thinking of using a CPT / CCT for that purpose (for ease of adding new sets of data in the future) but am unable to dynamically link the data to those hidden form fields (based on the chosen year).
So to put straight:
I have a "year" dropdown field, which I want to be dynamically populated (list of stored CPT's / CCT's)
And then I have a hidden "deduction value" fields, which values I want to change/set, with corresponding values from "year" CPT/CCT.
the functionality
Custom data structure consists of: year, deduction A, deduction B, deduction C etc
Form looks more or less like this:
1) year (dropdown) - based on the entries in custom data structure (that works)
2) revenue (input field)
3) question 1 (yes/no radio)
4) question 2 (yes/no radio)
5) question 3 (yes/no radio)
6) deduction A (hidden) - dynamically set value from the custom data, based on the selected year
7) deduction B (hidden) - dynamically set value from the custom data, based on the selected year
8) deduction C (hidden) - dynamically set value from the custom data, based on the selected year
9) calculated field
and the logic behind it:
if question 1 = yes
show question 2
fill "deduction A" field for chosen year (otherwise 0)
if question 2 = yes AND question 1 = yes
fill "deduction B" field for chosen year (otherwise 0)
if question 3 = yes
fill "deduction C" field for chosen year (otherwise 0)
-- OR --
allow to dynamically set the radio (or any form field) values (so that those intermediate hidden firlds are not necessary)
-- OR --
allow to set (any) field value based on another field's value - so that
question 1 "yes" = deduction A (using conditional block)
and the deduction A is dynamically populated.
And even it if's not, having multiple forms doing the same calculations, but on a different constants, it'd be super easy to just clone one, quickly edit the hidden constants and be done with it (instead of editing each and every radio, input, conditional etc)
examples
working (non-WP) form
The working example of such calculator can be found here (unfortunately only in Dutch): https://www.berekenhet.nl/ondernemen/netto-inkomen-ondernemer.html/
It looks simple, but the underlying maths and logic is not (for a form, that is).
I could provide the exact logic and calculations required to make it work, as an example of the complexity (not a help request as I'd be able to implement it myself, once JetForms will allow that kind of magic)
WP form plugins
There are other WP form builders out there that kinda-almost have it:
Gravity Forms:
has the ability to allow any field to be dynamically populated via:
query strings
shortcode
hooks
has following (well documented) methods of accessing forms and form data:
hooks
PHP API
REST API
database
Formidable Forms:
allows form field to take a value of another form field
the problem
I have a client that is a financial advisor and he tasked me with implementing an income calculator for his business clients. The values for calculating the outcome change, depending on a tax year, but the formula to calculate it is always the same.
So the first form field needs to be year and based on the chosen year, the (hidden) fileds containing the specific values to calculate the outcome would need to be populated.
I was thinking of using a CPT / CCT for that purpose (for ease of adding new sets of data in the future) but am unable to dynamically link the data to those hidden form fields (based on the chosen year).
So to put straight: I have a "year" dropdown field, which I want to be dynamically populated (list of stored CPT's / CCT's) And then I have a hidden "deduction value" fields, which values I want to change/set, with corresponding values from "year" CPT/CCT.
the functionality
Custom data structure consists of: year, deduction A, deduction B, deduction C etc
Form looks more or less like this: 1) year (dropdown) - based on the entries in custom data structure (that works) 2) revenue (input field) 3) question 1 (yes/no radio) 4) question 2 (yes/no radio) 5) question 3 (yes/no radio) 6) deduction A (hidden) - dynamically set value from the custom data, based on the selected year 7) deduction B (hidden) - dynamically set value from the custom data, based on the selected year 8) deduction C (hidden) - dynamically set value from the custom data, based on the selected year 9) calculated field
and the logic behind it:
if question 1 = yes show question 2 fill "deduction A" field for chosen year (otherwise 0)
if question 2 = yes AND question 1 = yes fill "deduction B" field for chosen year (otherwise 0)
if question 3 = yes fill "deduction C" field for chosen year (otherwise 0)
-- OR --
allow to dynamically set the radio (or any form field) values (so that those intermediate hidden firlds are not necessary)
-- OR --
allow to set (any) field value based on another field's value - so that question 1 "yes" = deduction A (using conditional block) and the deduction A is dynamically populated. And even it if's not, having multiple forms doing the same calculations, but on a different constants, it'd be super easy to just clone one, quickly edit the hidden constants and be done with it (instead of editing each and every radio, input, conditional etc)
examples
working (non-WP) form
The working example of such calculator can be found here (unfortunately only in Dutch): https://www.berekenhet.nl/ondernemen/netto-inkomen-ondernemer.html/ It looks simple, but the underlying maths and logic is not (for a form, that is). I could provide the exact logic and calculations required to make it work, as an example of the complexity (not a help request as I'd be able to implement it myself, once JetForms will allow that kind of magic)
WP form plugins
There are other WP form builders out there that kinda-almost have it: