logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$5
Custom Widget Not Saving

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
}
}
?>

This question has been answered.

Mike McAlister | 10/31/11 at 8:40pm Edit


(1) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    10/31/11
    8:48pm
    Kailey Lampert says:

    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>

    • 10/31/11 8:55pm

      Mike McAlister says:

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

      Thanks Kailey!

      Mike

This question has expired.



Mike McAlister, Gabriel Reguly voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.