Custom Widget outputs the input but doesn’t save anything inside the textarea

Your primary issue isn’t with saving the data but displaying in the form if it has been saved. I rewrote the offending function:

  function form($instance) {
    $title = strip_tags( $instance['title'] );
    $info = esc_textarea( $instance['info'] );
    // var_dump($instance); // debug
    ?>
    <p>
      <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
      <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
    </p>
    <p>
    <label for="<?php echo $this->get_field_id('info'); ?>"><?php _e('Text Goes here:'); ?></label>
      <textarea class="widefat" rows="8" cols="10" id="<?php echo $this->get_field_id('info'); ?>" name="<?php echo $this->get_field_name('info'); ?>"><?php if (!empty($info)) echo $info; ?></textarea>
    <?php
  }

You should make the change suggest by @br3nt, though.

I don’t see any other issues except for some minor notices that you would see if you had debugging enabled

Leave a Comment