Radio Buttons in Widget
-
Hello, I am trying to incorporate some radio buttons in a widget I am doing and have run into a hiccup. When I save the selection does not save and on the front end the selection is not shown.. I am following the WP FooBar example but cant figure out how to get the radios working correctly, I’m sure its because I am not properly getting the values but like I said, I dont really know how to go about getting them. Below is a sample of what I am working with, can anyone chime in or faced the same problem in the past?
public function widget( $args, $instance ) { extract( $args ); $title = apply_filters( 'widget_title', $instance['title'] ); $rating = $instance['rating']; echo $before_widget; if ( ! empty( $title ) ) echo $before_title . $title . $after_title; echo '<p><strong>Rating:</strong> ' . $rating . '</p>'; echo $after_widget; } public function update( $new_instance, $old_instance ) { $instance = array(); $instance['rating'] = strip_tags( $new_instance['rating'] ); return $instance; } public function form( $instance ) { if ( isset( $instance[ 'rating' ] ) ) { $rating = $instance[ 'rating' ]; } else { $rating = __( '', 'text_domain' ); //do radio } ?> <p> <label for="<?php echo $this->get_field_id( 'rating' ); ?>"><?php _e( 'Rating:' ); ?></label> <input type="radio" id="<?php echo $this->get_field_id( 'rating' ); ?>" name="<?php echo $this->get_field_name( 'rating' ); ?>" value="<?php echo esc_attr( $rating ); ?>">1<br> <input type="radio" id="<?php echo $this->get_field_id( 'rating' ); ?>" name="<?php echo $this->get_field_name( 'rating' ); ?>" value="<?php echo esc_attr( $rating ); ?>">2<br> <input type="radio" id="<?php echo $this->get_field_id( 'rating' ); ?>" name="<?php echo $this->get_field_name( 'rating' ); ?>" value="<?php echo esc_attr( $rating ); ?>">3<br> <input type="radio" id="<?php echo $this->get_field_id( 'rating' ); ?>" name="<?php echo $this->get_field_name( 'rating' ); ?>" value="<?php echo esc_attr( $rating ); ?>">4<br> <input type="radio" id="<?php echo $this->get_field_id( 'rating' ); ?>" name="<?php echo $this->get_field_name( 'rating' ); ?>" value="<?php echo esc_attr( $rating ); ?>">5<br> </p> <?php } }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Radio Buttons in Widget’ is closed to new replies.