Hi Guys!
I'm trying to minimize the occurrence of "magic numbers" within my themes/plugins. I have several situations where I need to specify a form ID, and I'd like to create select boxes so that the appropriate forms can be specified from within an options page, rather than hard-coding them in a template. I'm looking for something similar to wp_dropdown_pages() or wp_dropdown_categories(), but for GF.
I noticed that this is implemented within the settings for user registration forms. I used that code as a starting point, but I'm not exactly sure how to properly use GFUserData() from within my plugin/theme options page. Can you prod me in the right direction?
Here is what I'm working with:
<?php $options = get_option( 'my_theme_settings' ); ?>
<label for="gfcustom_reg_form">Select the User Registration Form</label>
<select id="gfcustom_reg_form" name="gfcustom_reg_form">
<option value="">Select a form</option>
<?php
$available_forms = GFUserData::get_available_forms();
foreach($available_forms as $current_form) {
$selected = (absint($current_form->id) == $options["reg_form_id"]) ? 'selected="selected"' : '';
?>
<option value="<?php echo absint($current_form->id) ?>" <?php echo $selected; ?>><?php echo esc_html($current_form->title) ?></option>
<?php
}
?>
</select>