How can I add a radio button in my wordpress widget form? I have been able to add input fields that gets saved and works fine. But I am having trouble with radiobuttons. Anyone?
This is my code for input field:
<p><label for="<?php echo $this->get_field_id('id'); ?>"><?php _e('Video ID:'); ?>
<input class="widefat" id="<?php echo $this->get_field_id('id'); ?>"
name="<?php echo $this->get_field_name('id'); ?>"
type="text" value="<?php echo $id; ?>" /></label></p>
and this is my radio button
<input type="radio" name="video_size" value="small"> Small<br>
<input type="radio" name="video_size" value="full" checked> Full
Create each radio button and make sure they are under the same “group”. The following is a basic HTML version of what you want.
Take note of the
name="group1"— this groups the two selections together so you can choose one or the other.checkedmarks the default selection when the radio buttons load.The WordPress version of this will require some logic to check what select the user has made. You will need to check if small or full is selected and have it supplement the checked attribute accordingly.
For instance