Title: Widget and  save problem
Last modified: August 20, 2016

---

# Widget and save problem

 *  [jepser](https://wordpress.org/support/users/jepser/)
 * (@jepser)
 * [15 years ago](https://wordpress.org/support/topic/widget-and-save-problem/)
 * Hi! I have the following code of a widget where I want to save the value: 1, 
   2, 3, and depending of the case load an image. The problem is that the value 
   isn’t saved.
 *     ```
       class noteWidget extends WP_Widget {
           /** constructor */
           function noteWidget() {
               parent::WP_Widget(false, $name = 'Note Widget');
           }
   
           /** @see WP_Widget::widget */
           function widget($args, $instance) {
               extract( $args );
               $note = $instance['note'];
               ?>
               	<pre><?php print_r($instance); ?></pre>
               		<?php echo $before_widget;
       					switch ($note){
       						case '1':
       							echo '<img src="' . get_bloginfo('stylesheet_directory') .'/images/note1.png" alt="Note 1" />';
       						break;
       						case '2':
       							echo '<img src="' . get_bloginfo('stylesheet_directory') .'/images/note2.png" alt="Note 2" />';
       						break;
       						case '3';
       							echo '<img src="' . get_bloginfo('stylesheet_directory') .'/images/note3.png" alt="Note 3" />';
       						break;
       					}
       				?>
                       <?php echo $after_widget; ?>
               <?php
           }
   
           /** @see WP_Widget::update */
           function update($new_instance, $old_instance) {
       	$instance = $old_instance;
       	$instance['note'] = strip_tags($new_instance['note']);
               return $instance;
           }
   
           /** @see WP_Widget::form */
           function form($instance) {
               $note = esc_attr($instance['note']);
               ?>
               <pre><?php print_r($instance); ?></pre>
                <p>
                 <label for="<?php echo $this->get_field_id('note'); ?>"><?php _e('Choose a note:'); ?></label>
                 <select id="<?php echo $this->get_field_id('note'); ?>" name="<?php echo $this->get_field_id('note'); ?>" class="widefat">
                 	<option value="1" <?php if($instance['format'] == '1') echo 'selected="selected"'; ?>>Note 1</option>
                   <option value="2" <?php if($instance['format'] == '2') echo 'selected="selected"'; ?>>Note 2</option>
                   <option value="3" <?php if($instance['format'] == '3') echo 'selected="selected"'; ?>>Note 3</option>
                 </select>
               </p>
               <?php
           }
   
       } // class noteWidget
       ```
   

The topic ‘Widget and save problem’ is closed to new replies.

## Tags

 * [select](https://wordpress.org/support/topic-tag/select/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * 0 replies
 * 1 participant
 * Last reply from: [jepser](https://wordpress.org/support/users/jepser/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/widget-and-save-problem/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
