PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

List forms in dropdown within options pages

  1. 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>
    Posted 13 years ago on Wednesday February 9, 2011 | Permalink
  2. Hi Wil,

    Here is a quick and dirty function that will generate a list of the Gravity Forms.

    http://pastie.org/1547182

    If you let me know specifically what you want to do with the GFUserData class I can better advise its use. :)

    Posted 13 years ago on Thursday February 10, 2011 | Permalink
  3. Perfect! Thank you.

    If you let me know specifically what you want to do with the GFUserData class I can better advise its use. :)

    Whoops. Yep, I was off there. Didn't need GFUserData. It was this that I was after: $forms = RGFormsModel::get_forms(); Nailed it!

    Posted 13 years ago on Thursday February 10, 2011 | Permalink