So, i successfully managed to add a drop down option, the problem is when i click save all of the options are removed, however the chosen option is implemented successfully.
Here is the relevant code:
function widget($args, $instance) {
extract( $args );
$pfxattribution = $instance['pfx-attribution'];
}
<p>
<label for="<?php echo $this->get_field_id('pfx-attribution'); ?>"><?php _e('Choose attribution:'); ?></label>
<select id="<?php echo $this->get_field_id('pfx-attribution'); ?>" name="<?php echo $this->get_field_name('pfx-attribution'); ?>" class="widefat" />
<option>Purefx</option>
<option>Foreign Exchange</option>
<option>Currency Exchange</option>
</select>
</p>
function update($new_instance, $old_instance) {
// Get the old values
$instance = $old_instance;
// Update with any new values (and sanitise input)
$instance['pfx-attribution'] = strip_tags( $new_instance['pfx-attribution'] );
return $instance;
}
Any help is greatly appreciated
Danny, this is pretty much lifted straight from a plug-in I’ve made:
Without seeing the rest of your code I can’t be sure the root of the problem, but it could be the form is not wrapped inside the form function. If the above doesn’t seem to work for you, perhaps pastie your Widget Class?
I should perhaps add that my widget class has a variable
w_arg
, an array of defaults! E.g.Your
<option>
s needvalue=
or they do not send any value…essentially right nowvalue=''
, which is, I’d bet, what you’re seeing.Your
<select>
should not have avalue
attribute, nor thetype="text"
attribute.