widget control form problem: works but then breaks after save (2 posts)

  1. chilinut
    Posted 3 years ago #

    Hi, I am a little new to authoring widgets. I am working on a widget that displays images from a category you select. I have a dropdown list of categories. the problem I am having is that when you load the widget control panel, the dropdown is functional; it displays properly and you can sucessfully select a category. when you hit save, it does in fact save your selection, but then the dropdown list becomes an empty dropown with a single blank item. When you refresh, it loads properly again. I have no idea what is going on! Here is that chunk of my widget form code:

      <label for="<?php echo $this->get_field_id('whichCat'); ?>">
      <select id="<?php echo $this->get_field_id('whichCat'); ?>" name="<?php echo $this->get_field_name('whichCat'); ?>" />
      	//lets try and list some categories
     $categories = get_categories();
    foreach ($categories as $cat) {
    //set up the option in the drop down
    echo "<option value=".$cat->slug.">";
    echo $cat->name."</option>";


  2. BigWilliam
    Posted 3 years ago #

    I had the exact same issue! But it was a syntax error - notice your select tag, it should not have /> at the end of it.

    i.e. change it to this

    <select id="<?php echo $this->get_field_id('whichCat'); ?>" name="<?php echo $this->get_field_name('whichCat'); ?>" >

Topic Closed

This topic has been closed to new replies.

About this Topic