Are you interested in incorporating field values for elements such as Dropdown, Checkbox, and Multiple Choice fields? By default, these fields solely allow for labeling each option. However, in this tutorial, we’ll demonstrate how to append an extra field to accommodate values alongside labels.
Adding the snippet to add field values
To begin, you’ll need to add this snippet to your site. If you need assistance in how to add snippets to your site, please see this tutorial.
/** * Show values in Dropdown, checkboxes, and Multiple Choice. * * @link https://wpforms.com/developers/add-field-values-for-dropdown-checkboxes-and-multiple-choice-fields/ */ add_filter( 'wpforms_fields_show_options_setting', '__return_true' );
Creating your form
Next, you’ll need to create your form and add your Dropdown, Checkbox, or Multiple Choice form field. In this tutorial, we’re adding a dropdown field of color choices.
If you need help in creating your form, please see this documentation.
Enabling the Show Value setting in the form builder
Once you’ve added your Dropdown, Checkbox or Multiple Choice form field and entered your choice options, click on the Advanced tab and click the toggle to Show Values and click Save on the form to save the changes.
When you go back to the General tab, you’ll see you can add additional field values to each option in the dropdown and re-save the form.
While the raw value is stored in the database entry, it’s not included in the {all_fields}
Smart Tag for email notifications, when viewing the entry in WordPress admin, or within CSV exports.
To display the value for a field in either a form’s confirmation message or notification email, you’ll need to use the following Smart Tag format:
{field_value_id="X"}
Just replace the X with the field ID, and this Smart Tag will automatically pull the value for any selected option(s) in that field. For assistance in finding your field ID, please review this tutorial.
And that’s it! You’ve now successfully added an additional field to hold values in your Dropdown, Checkboxes, and Multiple Choice form fields. Would you like to process Smart Tags in the Checkbox field label? Our article on How to Process Smart Tags in Checkbox Labels will walk you through how to achieve this.
Filter Reference
wpforms_fields_show_options_setting
FAQ
Q: Can I bulk add options to the Show Values?
A: Unfortunately no. When using the Show Values option for these fields, you’ll need to manually set your options for each.