mardi 3 juin 2014

How to set the default value as the saved value once a form of widget is saved?


Vote count:

0




I tried doing this for the function form :



<?php
function form(){

//Set up some default widget settings.

$defaults = array( 'uid' => __('121232', 'example'), 'height' => __('250px', 'example'), 'width' => __('170px', 'example') );
$instance = wp_parse_args( (array) $instance, $defaults );
?>
<p>
<label for="<?php echo $this->get_field_id( 'uid' ); ?>"><?php _e('User ID:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'uid' ); ?>" name="<?php echo $this->get_field_name( 'uid' ); ?>" value="<?php echo $instance['uid']; ?>" style="width:100%;" />
</p>

<p>
<label for="<?php echo $this->get_field_id( 'height' ); ?>"><?php _e('Height:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'height' ); ?>" name="<?php echo $this->get_field_name( 'height' ); ?>" value="<?php echo $instance['height']; ?>" style="width:100%;" />
</p>

<p>
<label for="<?php echo $this->get_field_id( 'width' ); ?>"><?php _e('Width:', 'example'); ?></label>
<input id="<?php echo $this->get_field_id( 'width' ); ?>" name="<?php echo $this->get_field_name( 'width' ); ?>" value="<?php echo $instance['width']; ?>" style="width:100%;" />
</p>

<?php
}

?>


I can use the default values as I have given, but after clicking the on save button with some other values in form, it returns into the previous default values. In the front-end, the widget is working fine along with the values I have chosen manually, but in the admin panel, the form is showing the default values as it's in the code.



asked 23 secs ago






Aucun commentaire:

Enregistrer un commentaire