Dynamically Populating a Drop Down with Static Values Conditional on a Value Entered in a Number Field

Loving the Gravity Forms plugins and configuration seems to have been a breeze, but I’m stuck on a little niggle. I have a form that has to calculate interest on a principal (and later generate documentation using PDF form). I could solve this issue with conditionally showing 1 of three dropdown fields on the form, but that seems to have a knock on effect requiring a LOT of conditional work in the PDFForm template. I would rather solve this ‘upstream’.

A principal loan amount is entered in a number field (Field ID 10). The dropdown field showing interest rates is Field ID 49.

If the number entered in FIELD ID 10 is under 10,000, Field ID 49 needs to offer a single interest rate.

Label = 17.50% Value = 17.50

If the number entered in FIELD ID 10 is between 10,000 & 20,000, Field ID 49 needs to offer 2 interest rates.

Label = 16.50% Value = 16.50
Label = 14.00% Value = 14.00

If the number entered in FIELD ID 10 is over 20,000 Field ID 49 needs to offer 2 interest rates.

Label = 15.50% Value = 15.50
Label = 13.00% Value = 13.00

The only other relevant post I’ve found is this one, but as the only advice offered was to display 1 of 2 dropdown fields conditionally, a coding solution was not forthcoming.

I’ll be honest, though competent in many other areas of coding, my php / modding WP with hooks etc knowledge is virtually nil. I suspect it’s a simple bit of code for this one niggle, and requiring a plugin would be considered overkill.

If somebody has previously coded a nigh-identical solution and can offer it up, it would save a very time-constrained individual a tonne of dead-ends and stress. Thanks in advance.

Hi Royston,

This is possible with our GP Populate Anything Perk. Here is a video demo of a similar setup

You can get in touch with us here if you have any questions

Best,

Thanks for your reply, Sam. As the site already has considerable ongoing license commitments, I’m hoping that somebody can help out with some example code in the first instance, rather than look at an additional license cost.

Plus … I’ll hopefully learn something :slight_smile:

1 Like

Hi Royston (@user5f91849c4f3ce182),

I have included the JSON version of a test form that consolidates the three radio button selections (dropdown has a default selection, which doesn’t work with this solution) back into a single field that contains the interest rate the user selected. The approach still has the three versions of the Interest Rate question, but by consolidating the selected value back into a single field, it should simplify the logic to create the PDF document. The IR Final field that is currently visible on the form should probably be hidden, but I left it visible so you can see it work on the form.

The approach is to show/hide a number field based on the selection made from the radio buttons. One number field for each possible Interest Rate value (IR1-IR5 in this case). Then there is one additional number field (IR Final) that adds up all the values from the Interest Rate number fields. Because only one of the fields is actually ‘shown’, that is the only value that gets added in the IR Final field.

I fully realize that this does not answer the problem statement in the title, but I hope it provides an alternate solution to your described problem.

This technique can be utilized for many scenarios, including for complex conditional logic, or for identifying if a question was answered, which can then be used to suppress, let’s say, the submit button. In other words you can do some pre-qualifying based on responses on the form and control who can submit a form. If used with HTML blocks for providing conditional feedback to the user, it can be very valuable in the right setting.

Here is the form (JSON) that can be saved as a JSON file and imported into Gravity Forms using the Import Forms functionality:
{“0”:{“title”:“Test(2)”,“description”:"",“labelPlacement”:“top_label”,“descriptionPlacement”:“below”,“button”:{“type”:“text”,“text”:“Submit”,“imageUrl”:""},“fields”:[{“type”:“number”,“id”:11,“formId”:33,“label”:“Loan Amount”,“adminLabel”:“Principal”,“isRequired”:false,“size”:“large”,“errorMessage”:"",“visibility”:“visible”,“inputs”:null,“numberFormat”:“decimal_dot”,“description”:"",“allowsPrepopulate”:false,“inputMask”:false,“inputMaskValue”:"",“inputMaskIsCustom”:false,“maxLength”:"",“inputType”:"",“labelPlacement”:"",“descriptionPlacement”:"",“subLabelPlacement”:"",“placeholder”:"",“cssClass”:"",“inputName”:"",“noDuplicates”:false,“defaultValue”:"",“enableAutocomplete”:false,“autocompleteAttribute”:"",“choices”:"",“conditionalLogic”:"",“enableCalculation”:false,“rangeMin”:"",“rangeMax”:"",“productField”:"",“layoutGridColumnSpan”:"",“enableEnhancedUI”:0,“layoutGroupId”:“88526091”,“fields”:"",“displayOnly”:"",“multipleFiles”:false,“maxFiles”:"",“calculationFormula”:"",“calculationRounding”:"",“disableQuantity”:false,“displayAllCategories”:false,“useRichTextEditor”:false,“errors”:[]},{“type”:“radio”,“id”:28,“formId”:33,“label”:“Interest Rate”,“adminLabel”:“IR Choice 1”,“isRequired”:false,“size”:“large”,“errorMessage”:"",“visibility”:“visible”,“inputs”:null,“choices”:[{“text”:“17.50%”,“value”:“17.50%”,“isSelected”:false,“price”:""}],“description”:"",“allowsPrepopulate”:false,“inputMask”:false,“inputMaskValue”:"",“inputMaskIsCustom”:false,“maxLength”:"",“inputType”:"",“labelPlacement”:"",“descriptionPlacement”:"",“subLabelPlacement”:"",“placeholder”:"",“cssClass”:"",“inputName”:"",“noDuplicates”:false,“defaultValue”:"",“enableAutocomplete”:false,“autocompleteAttribute”:"",“conditionalLogic”:{“enabled”:true,“actionType”:“show”,“logicType”:“all”,“rules”:[{“fieldId”:“11”,“operator”:"<",“value”:“10000”}]},“productField”:"",“layoutGridColumnSpan”:12,“enableOtherChoice”:"",“enablePrice”:"",“enableEnhancedUI”:0,“multipleFiles”:false,“maxFiles”:"",“calculationFormula”:"",“calculationRounding”:"",“enableCalculation”:"",“disableQuantity”:false,“displayAllCategories”:false,“useRichTextEditor”:false,“errors”:[],“fields”:"",“displayOnly”:"",“layoutGroupId”:“fee80b1f”},{“type”:“radio”,“id”:29,“formId”:33,“label”:“Interest Rate”,“adminLabel”:“IR Choice 2”,“isRequired”:false,“size”:“large”,“errorMessage”:"",“visibility”:“visible”,“inputs”:null,“choices”:[{“text”:“16.50%”,“value”:“16.50%”,“isSelected”:false,“price”:""},{“text”:“14.00%”,“value”:“14.00%”,“isSelected”:false,“price”:""}],“description”:"",“allowsPrepopulate”:false,“inputMask”:false,“inputMaskValue”:"",“inputMaskIsCustom”:false,“maxLength”:"",“inputType”:"",“labelPlacement”:"",“descriptionPlacement”:"",“subLabelPlacement”:"",“placeholder”:"",“cssClass”:"",“inputName”:"",“noDuplicates”:false,“defaultValue”:"",“enableAutocomplete”:false,“autocompleteAttribute”:"",“conditionalLogic”:{“enabled”:true,“actionType”:“show”,“logicType”:“all”,“rules”:[{“fieldId”:“11”,“operator”:">",“value”:“9999.99”},{“fieldId”:“11”,“operator”:"<",“value”:“20000”}]},“productField”:"",“layoutGridColumnSpan”:12,“enableOtherChoice”:"",“enablePrice”:"",“enableEnhancedUI”:0,“multipleFiles”:false,“maxFiles”:"",“calculationFormula”:"",“calculationRounding”:"",“enableCalculation”:"",“disableQuantity”:false,“displayAllCategories”:false,“useRichTextEditor”:false,“errors”:[],“fields”:"",“displayOnly”:"",“layoutGroupId”:“0518f690”},{“type”:“radio”,“id”:30,“formId”:33,“label”:“Interest Rate”,“adminLabel”:“IR Choice 3”,“isRequired”:false,“size”:“large”,“errorMessage”:"",“visibility”:“visible”,“inputs”:null,“choices”:[{“text”:“15.50%”,“value”:“15.50%”,“isSelected”:false,“price”:""},{“text”:“13.00%”,“value”:“13.00%”,“isSelected”:false,“price”:""}],“description”:"",“allowsPrepopulate”:false,“inputMask”:false,“inputMaskValue”:"",“inputMaskIsCustom”:false,“maxLength”:"",“inputType”:"",“labelPlacement”:"",“descriptionPlacement”:"",“subLabelPlacement”:"",“placeholder”:"",“cssClass”:"",“inputName”:"",“noDuplicates”:false,“defaultValue”:"",“enableAutocomplete”:false,“autocompleteAttribute”:"",“conditionalLogic”:{“enabled”:true,“actionType”:“show”,“logicType”:“all”,“rules”:[{“fieldId”:“11”,“operator”:">",“value”:“19999.99”}]},“productField”:"",“layoutGridColumnSpan”:12,“enableOtherChoice”:"",“enablePrice”:"",“enableEnhancedUI”:0,“multipleFiles”:false,“maxFiles”:"",“calculationFormula”:"",“calculationRounding”:"",“enableCalculation”:"",“disableQuantity”:false,“displayAllCategories”:false,“useRichTextEditor”:false,“errors”:[],“fields”:"",“displayOnly”:"",“layoutGroupId”:“9ff1cc3c”},{“type”:“number”,“id”:23,“formId”:33,“label”:“IR1”,“adminLabel”:"",“isRequired”:false,“size”:“large”,“errorMessage”:"",“visibility”:“hidden”,“inputs”:null,“numberFormat”:“decimal_dot”,“description”:"",“allowsPrepopulate”:false,“inputMask”:false,“inputMaskValue”:"",“inputMaskIsCustom”:false,“maxLength”:"",“inputType”:"",“labelPlacement”:"",“descriptionPlacement”:"",“subLabelPlacement”:"",“placeholder”:"",“cssClass”:"",“inputName”:"",“noDuplicates”:false,“defaultValue”:“17.5”,“enableAutocomplete”:false,“autocompleteAttribute”:"",“choices”:"",“conditionalLogic”:{“enabled”:true,“actionType”:“show”,“logicType”:“all”,“rules”:[{“fieldId”:“28”,“operator”:“is”,“value”:“17.50%”}]},“enableCalculation”:false,“rangeMin”:"",“rangeMax”:"",“productField”:"",“layoutGridColumnSpan”:"",“enableEnhancedUI”:0,“multipleFiles”:false,“maxFiles”:"",“calculationFormula”:"",“calculationRounding”:"",“disableQuantity”:false,“displayAllCategories”:false,“useRichTextEditor”:false,“errors”:[],“fields”:"",“displayOnly”:"",“layoutGroupId”:“2c51ed10”},{“type”:“number”,“id”:24,“formId”:33,“label”:“IR2”,“adminLabel”:"",“isRequired”:false,“size”:“large”,“errorMessage”:"",“visibility”:“hidden”,“inputs”:null,“numberFormat”:“decimal_dot”,“description”:"",“allowsPrepopulate”:false,“inputMask”:false,“inputMaskValue”:"",“inputMaskIsCustom”:false,“maxLength”:"",“inputType”:"",“labelPlacement”:"",“descriptionPlacement”:"",“subLabelPlacement”:"",“placeholder”:"",“cssClass”:"",“inputName”:"",“noDuplicates”:false,“defaultValue”:“16.5”,“enableAutocomplete”:false,“autocompleteAttribute”:"",“choices”:"",“conditionalLogic”:{“enabled”:true,“actionType”:“show”,“logicType”:“all”,“rules”:[{“fieldId”:“29”,“operator”:“is”,“value”:“16.50%”}]},“enableCalculation”:false,“rangeMin”:"",“rangeMax”:"",“productField”:"",“layoutGridColumnSpan”:"",“enableEnhancedUI”:0,“multipleFiles”:false,“maxFiles”:"",“calculationFormula”:"",“calculationRounding”:"",“disableQuantity”:false,“displayAllCategories”:false,“useRichTextEditor”:false,“errors”:[],“fields”:"",“displayOnly”:"",“layoutGroupId”:“a94b9fd4”},{“type”:“number”,“id”:25,“formId”:33,“label”:“IR3”,“adminLabel”:"",“isRequired”:false,“size”:“large”,“errorMessage”:"",“visibility”:“hidden”,“inputs”:null,“numberFormat”:“decimal_dot”,“description”:"",“allowsPrepopulate”:false,“inputMask”:false,“inputMaskValue”:"",“inputMaskIsCustom”:false,“maxLength”:"",“inputType”:"",“labelPlacement”:"",“descriptionPlacement”:"",“subLabelPlacement”:"",“placeholder”:"",“cssClass”:"",“inputName”:"",“noDuplicates”:false,“defaultValue”:“14”,“enableAutocomplete”:false,“autocompleteAttribute”:"",“choices”:"",“conditionalLogic”:{“enabled”:true,“actionType”:“show”,“logicType”:“all”,“rules”:[{“fieldId”:“29”,“operator”:“is”,“value”:“14.00%”}]},“enableCalculation”:false,“rangeMin”:"",“rangeMax”:"",“productField”:"",“layoutGridColumnSpan”:"",“enableEnhancedUI”:0,“multipleFiles”:false,“maxFiles”:"",“calculationFormula”:"",“calculationRounding”:"",“disableQuantity”:false,“displayAllCategories”:false,“useRichTextEditor”:false,“errors”:[],“fields”:"",“displayOnly”:"",“layoutGroupId”:“f84ad9c1”},{“type”:“number”,“id”:26,“formId”:33,“label”:“IR4”,“adminLabel”:"",“isRequired”:false,“size”:“large”,“errorMessage”:"",“visibility”:“hidden”,“inputs”:null,“numberFormat”:“decimal_dot”,“description”:"",“allowsPrepopulate”:false,“inputMask”:false,“inputMaskValue”:"",“inputMaskIsCustom”:false,“maxLength”:"",“inputType”:"",“labelPlacement”:"",“descriptionPlacement”:"",“subLabelPlacement”:"",“placeholder”:"",“cssClass”:"",“inputName”:"",“noDuplicates”:false,“defaultValue”:“15.5”,“enableAutocomplete”:false,“autocompleteAttribute”:"",“choices”:"",“conditionalLogic”:{“enabled”:true,“actionType”:“show”,“logicType”:“all”,“rules”:[{“fieldId”:“30”,“operator”:“is”,“value”:“15.50%”}]},“enableCalculation”:false,“rangeMin”:"",“rangeMax”:"",“productField”:"",“layoutGridColumnSpan”:"",“enableEnhancedUI”:0,“multipleFiles”:false,“maxFiles”:"",“calculationFormula”:"",“calculationRounding”:"",“disableQuantity”:false,“displayAllCategories”:false,“useRichTextEditor”:false,“errors”:[],“fields”:"",“displayOnly”:"",“layoutGroupId”:“f892f5a4”},{“type”:“number”,“id”:27,“formId”:33,“label”:“IR5”,“adminLabel”:"",“isRequired”:false,“size”:“large”,“errorMessage”:"",“visibility”:“hidden”,“inputs”:null,“numberFormat”:“decimal_dot”,“description”:"",“allowsPrepopulate”:false,“inputMask”:false,“inputMaskValue”:"",“inputMaskIsCustom”:false,“maxLength”:"",“inputType”:"",“labelPlacement”:"",“descriptionPlacement”:"",“subLabelPlacement”:"",“placeholder”:"",“cssClass”:"",“inputName”:"",“noDuplicates”:false,“defaultValue”:“13”,“enableAutocomplete”:false,“autocompleteAttribute”:"",“choices”:"",“conditionalLogic”:{“enabled”:true,“actionType”:“show”,“logicType”:“all”,“rules”:[{“fieldId”:“30”,“operator”:“is”,“value”:“13.00%”}]},“enableCalculation”:false,“rangeMin”:"",“rangeMax”:"",“productField”:"",“layoutGridColumnSpan”:12,“enableEnhancedUI”:0,“layoutGroupId”:“ace45d8f”,“multipleFiles”:false,“maxFiles”:"",“calculationFormula”:"",“calculationRounding”:"",“disableQuantity”:false,“displayAllCategories”:false,“useRichTextEditor”:false,“errors”:[],“fields”:"",“displayOnly”:""},{“type”:“number”,“id”:22,“formId”:33,“label”:“IR Final”,“adminLabel”:"",“isRequired”:false,“size”:“large”,“errorMessage”:"",“visibility”:“visible”,“inputs”:null,“numberFormat”:“decimal_dot”,“description”:"",“allowsPrepopulate”:false,“inputMask”:false,“inputMaskValue”:"",“inputMaskIsCustom”:false,“maxLength”:"",“inputType”:"",“labelPlacement”:"",“descriptionPlacement”:"",“subLabelPlacement”:"",“placeholder”:"",“cssClass”:"",“inputName”:"",“noDuplicates”:false,“defaultValue”:"",“enableAutocomplete”:false,“autocompleteAttribute”:"",“choices”:"",“conditionalLogic”:"",“enableCalculation”:true,“rangeMin”:"",“rangeMax”:"",“productField”:"",“layoutGridColumnSpan”:12,“enableEnhancedUI”:0,“multipleFiles”:false,“maxFiles”:"",“calculationFormula”:"{IR5:27} + {IR4:26} + {IR3:25} + {IR2:24} + {IR1:23}",“calculationRounding”:"",“disableQuantity”:false,“displayAllCategories”:false,“useRichTextEditor”:false,“fields”:"",“displayOnly”:"",“layoutGroupId”:“6966b6fc”,“errors”:[]}],“version”:“2.5.8”,“id”:33,“useCurrentUserAsAuthor”:true,“postContentTemplateEnabled”:false,“postTitleTemplateEnabled”:false,“postTitleTemplate”:"",“postContentTemplate”:"",“lastPageButton”:null,“pagination”:null,“firstPageCssClass”:null,“nextFieldId”:31,“subLabelPlacement”:“below”,“cssClass”:"",“enableHoneypot”:true,“enableAnimation”:false,“save”:{“enabled”:false,“button”:{“type”:“link”,“text”:“Save and Continue Later”}},“limitEntries”:false,“limitEntriesCount”:"",“limitEntriesPeriod”:"",“limitEntriesMessage”:"",“scheduleForm”:false,“scheduleStart”:"",“scheduleStartHour”:"",“scheduleStartMinute”:"",“scheduleStartAmpm”:"",“scheduleEnd”:"",“scheduleEndHour”:"",“scheduleEndMinute”:"",“scheduleEndAmpm”:"",“schedulePendingMessage”:"",“scheduleMessage”:"",“requireLogin”:false,“requireLoginMessage”:"",“confirmations”:[{“id”:“572bc55c66f2d”,“name”:“Default Confirmation”,“isDefault”:true,“type”:“message”,“message”:“Thanks for contacting us! We will get in touch with you shortly.”,“url”:"",“pageId”:"",“queryString”:""}],“notifications”:[{“isActive”:true,“id”:“572bc55c66a50”,“name”:“Admin Notification”,“service”:“wordpress”,“event”:“form_submission”,“to”:"{Admin}",“toType”:“email”,“bcc”:"",“subject”:“New submission from {form_title}”,“message”:"{all_fields}",“from”:"",“fromName”:"",“replyTo”:"",“routing”:[[]],“conditionalLogic”:null,“disableAutoformat”:false,“toEmail”:"{Admin}",“toField”:"",“notification_conditional_logic_object”:"",“notification_conditional_logic”:“0”,“cc”:"",“enableAttachments”:false}]},“version”:“2.5.8”}

1 Like

This is what I was going to say: use conditionals to expose intermediate fields and have them set a hidden field that is the one you actually work from on the backend. It doesn’t require any more plugins and wouldn’t even require you to change much of the work you’ve done.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.