Can't catch radio button in widget
-
I want to create a custom widget with 3 simple radio buttons, so i made class with WidgetName, widget(), update(), form(). I will show update(), and form(), because i think they are important :
function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['default-image'] = $new_instance['default-image']; $instance['post-image'] = $new_instance['post-image']; $instance['link-image'] = $new_instance['link-image']; return $instance; }
function form( $instance ) { $defaults = array('default-image' => true, 'post-image' => false, 'link-image' => false ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <p> <input name="option" type="radio" <?php checked( $instance['default-image']); ?> id="<?php echo $this->get_field_id( 'default-image' ); ?>"/> <label for="<?php echo $this->get_field_id( 'default-image' ); ?>"><?php _e('Default image'); ?></label> </p> <p> <input name="option" type="radio" <?php checked( $instance['post-image']); ?> id="<?php echo $this->get_field_id( 'post-image' ); ?>" /> <label for="<?php echo $this->get_field_id( 'post-image' ); ?>"><?php _e('First post image'); ?></label> </p> <p> <input name="option" type="radio" <?php checked( $instance['link-image']); ?> id="<?php echo $this->get_field_id( 'link-image' ); ?>" /> <label for="<?php echo $this->get_field_id( 'link-image' ); ?>"><?php _e('Image from link', 'example'); ?></label> </p> <?php }
but in this scenario, when i refresh admin page on click on “Save” button, the current selection disappears. I’m new in wordpress and php, so sorry for “trivial” question. I will appreciate every help.
- The topic ‘Can't catch radio button in widget’ is closed to new replies.