Dropdown with next three years

By: Mitch Williams | Asked: 02/16/2024
ForumsCategory: How-toDropdown with next three years
Mitch Williams asked 3 months ago
I'm trying to create a dropdown field that automatically generates the following options: Current year
Current year plus one
Current year plus two In other words, the current year and the next two years as the options users can select.  Is there an easy way to do this? Thanks, Mitch Williams
Spoon River College
3 Answers
Victor Font answered 3 months ago
Yes, you can create a dropdown dynamically and dynamically change it's values, but you really need to think through how you're going to use the data because of entry edits are handled. I'll explain in detail in the comment below. Give me a few minutes to write your answer.
Victor Font replied 3 months ago

Formidable offers three types of drop downs, standard, dynamic, and lookup. Dynamic and lookup are populated with data from other forms. In fact, you can actually build a dynamic dropdown from a value that's on the same form as the dropdown. I use this technique with the Formidable Masterminds Developers Directory.

Standard dropdowns are part of Formidable Lite. Dynamic and Lookup are Pro fields. Standard dropdowns can be populated dynamically from just about any data source you choose, even data that isn't in WordPress.

To understand the issue you're going to run into with edits, you need to know how these dropdowns store their data. in the database. Standard dropdown can use separate values. If you don't want to use separate values, then the label is the value.

With your example you want current year, current year + 1, and current year + 2. This is not a problem. You have to create a PHP function that with serve as callbacks for two Formidable hooks, frm_setup_new_fields_vars and frm_setup_edit_fields_vars.

So let's say you start today, the values will be 2024, 2025, and 2026. Next year, the values will be 2025, 2026, and 2027. Any entries you have from this year where the value 2024 is saved will likely produce an error if you ever need to edit the record.

In Pro, dynamic fields rock because the store the entry id of the linked record creating a virtual relationship to every field in that record. In a view, you can literally display every field in the lookup record by the record number stored in a single dropdown. It's a great feature Formidable provides.

Lookup fields store text values of the lookup field, just like standard dropdowns do.

Rob LeVineRob LeVine answered 3 months ago
Add a drop-down element in your form and use https://formidableforms.com/knowledgebase/frm_setup_new_fields_vars/ to fill in the values via PHP.  NOTE: If this form will be used for editing entries and that field is editable, you'll need to also add the filter https://formidableforms.com/knowledgebase/frm_setup_edit_fields_vars/ and point it to the same function as the _new_.
Mitch Williams answered 3 months ago
Thanks for these suggestions.  Unfortunately I'm pretty inexperienced at writing/editing php code.  I've tried a couple approaches to this already, but have been unable to get them to work.   Any suggestions on where to get specific detailed instructions on how to create the code, how to customize it, and where to insert it?   Would I use a code snippet plugin to run the code site wide, and then call it using a shortcode somehow???   Appreciate the help.   Thanks.
Rob LeVineRob LeVine replied 3 months ago

Overview of how to use the hooks - https://formidableforms.com/knowledgebase/formidable-hooks/
Look at the examples here - https://formidableforms.com/knowledgebase/frm_setup_edit_fields_vars/
Or you can hire a developer - https://formidable-masterminds.com/developers-directory/
Personally, when I do a project for someone, I leave them with a Google Doc that explains how it was done so they can do it themselves the next time.

Mitch Williams replied 3 months ago

Thanks, Rob. I'll check these out.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right