Create and Use drop down boxes
-
Hi,
I am getting to grips with your framework and really like it so far. I am trying to create an options page with a drop down field that will let users select an item ‘original, light, dark’. When the user selects this I would like to use this value elsewhere.
I was wondering if you could help. I currently only have a text field rather than a drop down and it currently just outputs ‘Array’
My code is as follows:
function noou_swatches() { $data = get_option( 'APF_AdvancedSections' ); $value = isset( $data['repeatable_tabbed_section_2'] ) ? $data['my_text_field'] : $data['my_text_field']; echo "<div id='slideOut' class='clearfix".$data."'> <div id='slideClick'> <img src='".plugin_dir_url( __FILE__ ) . "/img/swatch-icon-rgb.png'> </div> <div id='slideOutContainer'> <div id='slideTitle'> NoouSwatches </div> <div id='slideContent'>"; $my_options = get_option( 'APF_AdvancedSections' ); foreach($my_options['repeatable_tabbed_section']['my_color'] as $idx => $color){ echo " <div id='swatch'> <div id='swatchIcon' style='background-color:" . $color . "'></div> <div id='swatchHex'>" . $color . "</div> </div>"; } echo " </div> <div id='slideFooter'> <a href='admin.php?page=advanced_sections'>+</a> </div> </div> </div> "; } add_action( 'all_admin_notices', 'noou_swatches' ); add_action( 'customize_register', 'noou_swatches' ); /* start option page */ if ( ! class_exists( 'AdminPageFramework' ) ) { include_once( dirname( __FILE__ ) . '/library/admin-page-framework.php' ); } // Extend the class class APF_AdvancedSections extends AdminPageFramework { // Define the setup() method to set how many pages, page titles and icons etc. public function setUp() { // Set the root menu $this->setRootMenuPage( 'Noou Swatches', plugin_dir_url( __FILE__ ) . 'img/menu-icon.png' ); // specifies to which parent menu to add. // Add the sub menus and the pages $this->addSubMenuItems( array( 'title' => 'Color Swatches', // the page and menu title 'page_slug' => 'advanced_sections' // the page slug ), array( 'title' => 'Options', 'page_slug' => 'noou_swatches_options' ) ); // Add form sections $this->addSettingSections( 'advanced_sections', // target page slug array( 'section_id' => 'repeatable_tabbed_section', 'section_tab_slug' => 'repeatable_sections', 'repeatable' => false, 'title' => 'Noou Swatches', 'description' => 'You can add/remove color swatches here. These will show up in the swatches panel to the right of all admin pages.', ) ); $this->addSettingSections( 'noou_swatches_options', // target page slug array( 'section_id' => 'repeatable_tabbed_section_2', 'section_tab_slug' => 'repeatable_sections_2', 'repeatable' => false, 'title' => 'Options', 'description' => 'This section is a repeatable tabbed section.', ) ); // Add form fields $this->addSettingFields( 'repeatable_tabbed_section', // target page slug array( 'field_id' => 'my_color', 'type' => 'color', 'title' => 'Color Swatches', 'repeatable' => true, 'sortable' => true, ) ); $this->addSettingFields( 'repeatable_tabbed_section_2', // target page slug array( // Single text field 'field_id' => 'my_text_field', 'type' => 'text', 'title' => 'Text', 'description' => 'Type something here.', ), array( // Submit button 'field_id' => 'submit_button', 'type' => 'submit', ) ); $this->setFooterInfoRight( '' ); } public function do_advanced_sections() { // do_ + page slug submit_button(); // Show the saved option value. // The extended class name is used as the option key. This can be changed by passing a custom string to the constructor. //echo '<h3>Options as an array</h4>'; //echo $this->oDebug->getArray( get_option( 'APF_AdvancedSections' ) ); //echo '<h3>Retrieve individual field values</h4>'; //echo '<pre>APF_AdvancedSections[repeatable_tabbed_section][1][my_color]: ' . AdminPageFramework::getOption( 'APF_AdvancedSections', array( 'repeatable_tabbed_section', '0', 'color' ), 'default color value' ) . '</pre>'; } } // Instantiate the class object. if ( is_admin() ) { new APF_AdvancedSections; }
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Create and Use drop down boxes’ is closed to new replies.