Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Widget Not Saving WordPress

  • SOLVED

Hi,
Quick and easy one here. I'm working on a custom note widget. Had it working with two text fields, but when I tried to change the second text field to a textarea, it stopped saving correctly. The title saves fine, but the textarea does not.

Any help is appreciated!
Mike



<?php
/*-----------------------------------------------------------------------------------*/
/* Note Widget
/*-----------------------------------------------------------------------------------*/

add_action( 'widgets_init', 'load_ok_note_widget' );

function load_ok_note_widget() {
register_widget( 'okay_note' );
}

class okay_note extends WP_Widget {

function okay_note() {
$widget_ops = array( 'classname' => 'ok-note', 'description' => __('Okay Note Widget', 'ok-note') );
$control_ops = array( 'width' => 200, 'height' => 350, 'id_base' => 'ok-note' );
$this->WP_Widget( 'ok-note', __('Okay Note Widget', 'ok-note'), $widget_ops, $control_ops );
}

function widget( $args, $instance ) {

extract( $args );
$notetitle = $instance['notetitle'];
$notecontent= $instance['notecontent'];
echo $before_widget;
?>
<div class="note">
<div class="inner-top-paper"></div>

<div class="inner-mid-paper">
<div class="textwidget"><span><?php echo $instance['notetitle']; ?></span>
<p><?php echo $instance['notecontent']; ?></p>
</div>
<div class="clear_0"></div>
</div>

<div class="inner-bottom-paper"></div>
</div><!-- note -->

<?php
echo $after_widget;
}

function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['notetitle'] = $new_instance['notetitle'];
$instance['notecontent'] = $new_instance['notecontent'];
return $instance;
}

function form($instance) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'notetitle' => '', 'notecontent' => '') );
$instance['notetitle'] = $instance['notetitle'];
$instance['notecontent'] = $instance['notecontent'];
?>
<p>
<label for="<?php echo $this->get_field_id('notetitle'); ?>">Note Title:
<input class="widefat" id="<?php echo $this->get_field_id('notetitle'); ?>" name="<?php echo $this->get_field_name('notetitle'); ?>" type="text" value="<?php echo $instance['notetitle']; ?>" /></label>
</p>

<p>
<label for="<?php echo $this->get_field_id('notecontent'); ?>">Note Message:
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('notecontent'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $notecontent; ?></textarea>
</p>

<?php
}
}
?>

Answers (1)

2011-11-01

Kailey Lampert answers:

For your textarea, try this:


<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('notecontent'); ?>" name="<?php echo $this->get_field_name('notecontent'); ?>"><?php echo $instance['notecontent']; ?></textarea>


Mike McAlister comments:

Jesus, I'm an idiot! I saw what I did wrong within seconds of posting this. That works though (obviously).

Thanks Kailey!

Mike