PHP Form: Select Categories
-
Refining my options panel and I want to offer the user the option to select certain categories from a drop down. This works – and even saves. However after the save the drop down list doesn’t “remember” the selection and if you save again changes are lost.
<select class="aselect" id="<?php echo $value['id']; ?>" name="<?php echo $value['id']; ?>"> <option value="0"><?php _e('Select a Category', 'thetimes'); ?></option> <?php global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); } } $categories = &get_categories('type=post&orderby=name&hide_empty=1'); if ($categories) { $find_select = $tt_catbox_1; foreach ($categories as $category) { $selected = (in_array($category->cat_ID, $find_select)) ? ' selected="selected"' : ''; echo '<option value="' . $category->cat_ID . '"' . $selected . '>' . $category->cat_name . '</option>' . "\n"; } } ?> </select>
$tt_catbox_1 contains the category ID
I’ve Googled and found the above code, however I can’t get the “SELECTED” to work quite right. I think I need to pull from the database the settings. How do I do that?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘PHP Form: Select Categories’ is closed to new replies.