• Hi, I got a litle script which display all pages you got in a multiple select on a theme options page. So far everything worked, but when I try want to display the ‘answers’ of that option I got two problems.

    1. I retrieve only 1 of all the options I chosen. E.G. I selected page with ID 5,3623 and 23. The layout will only show the latest option ( 23 ). I don’t know if it’s the Framework, or the code I use to retrieve the options.
    2. I want to display a “,” after each page ID. Not: 5 3623 23. But : 5,3623,23. Like foreach orso.

    FRAMEWORK

    <?php 
    
    function mytheme_add_admin() {
    
    global $themename, $shortname, $options ;
    
    if ( $_GET['page'] == basename(__FILE__) ) {
    
    if ( 'save' == $_REQUEST['action'] ) {
    
    foreach ($options as $value) {
    update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
    
    foreach ($options as $value) {
    if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
    
    header("Location: themes.php?page=theme-options.php&saved=true");
    die;
    
    } else if( 'reset' == $_REQUEST['action'] ) {
    
    foreach ($options as $value) {
    delete_option( $value['id'] ); }
    
    header("Location: themes.php?page=theme-options.php&reset=true");
    die;
    
    }
    }
    
    add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
    
    }
    
    function mytheme_admin() {
    
    global $themename, $shortname, $options;
    
    ?>
    
    <div id="wrap">
    
    <form method="post" action="" >
    
    <?php
    break;
    
    case 'excludepage':
    ?>
    
    <select id="topexclude" name="topexclude" multiple="multiple" style="height:150px;">
    <?php foreach($news_categories as $page) : ?>
    <option name="topexclude" value="<?php echo $page->ID; ?>" <?php if(is_array($val['topexclude']) && in_array($page->ID, $val['topexclude'])) echo ' selected="selected"'; ?>>
    <?php echo $page->post_title; ?>
    </option>
    <?php endforeach; ?>
    </select>
    
    <?php break;
    
    }
    }
    ?>
    
    <p class="submit">
    <input name="save" type="submit" value="Save changes" />
    <input type="hidden" name="action" value="save" />
    </p>
    
    </form>
    
    <?php
    }
    ?>

    THIS WILL ACTIVE THE EXCLUDEPAGE

    <?php
    
    $options = array (
    
    	array(	"name" => "Layout style",
    		"id" => "topexclude",
    		"desc" => "Click on the pages you want to exclude from the top navigation"
    		"type" => "excludepage" ),
    
    );
    ?>

    AND THIS CODE I USE TO SHOW EXCLUDEPAGE

    <?php echo get_option('topexclude');?>

    I think I need some expert help 😛

    – Steven

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter stevenoi

    (@stevenoi)

    bump…

    I am having the same problem, when I retrieve the value of a select form element with multiple values it only returns the last value selected and no others.

    Hah, figured it out moments after i posted this. Here’s were I was going wrong..

    When you make the select tell it you are going to expect the value as an array by putting “[]” at the end of the name parameter.

    Exampl:

    <select name=”MySelect[]”>

    This made it so i got an array returned as my value, although this isn’t the commented list i was expecting it’s actually much easier to use.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Theme options, select multiple’ is closed to new replies.