Using HTML_Quickform_hierselect

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Hi Everyone,

I've got a puzzler for you all that use PEAR's HTML_Quickform:

I've been using your HTML_QuickForm_hierselect in a PHP application I
have, and it's been working great, but I'm having a little issue I
can't seem to solve.  I have two select boxes, side by side, the first
one causing an action on the second.  The problem is, I'm trying to
use this in such a way that the first option in the second box is
always blank.

In context, we're using this in a Web links script.  When someone
wants to create a new link in the database, they fill out a basic form
using HTML_QuickForm, and then they get to choose which main and
sub-category the link belongs.  When they choose a main category, the
subcategories for that main category show up in the second select box.
 If the user chooses a main category that has sub-categories defined
for it, it's impossible for him to choose to simply put the link under
the main category _without_ forcing it to be in a subcategory, because
the HTML_QuickForm_hierselect for the second select dropdown is
automatically choosing the available subcategories, and doesn't give
an option for "null".

Here's some snippets of the script as we have it for the function to
make a new link:


    $sel =& $form->addElement('hierselect', 'link_pid', 'Category and



function getLinkSubcategories()
    require '';

        // open the db connection
        $conn = mysql_connect($config['dbhost'], $config['dbuser'],

        // check the db connection
        if (!$conn)
                die ("Could not connect to database.");

        // select the right db
        mysql_select_db($config['dbname'], $conn)
                or die ("Could not open database.");

        $query = "SELECT *
                          FROM sbclinks_cat
                          WHERE pid != '0'";

        $result = mysql_query($query)
                or die("Query failed: " . mysql_error());

    $link_subcats = array(""=>"Select a subcategory");

    while ($row = mysql_fetch_array($result)) {
           $link_subcats[$row[pid]][$row[id]] = $row[name];

        return $link_subcats;


So, say we have:

Main Category 1

If I just want to put a link into Main Category 1, I can't, because as
soon as I choose it in our first select box, SubCategory1a and
SubCategory1b show up in the second select box...and I am forced to
choose one of them.

Any help would be greatly appreciated.


Site Timeline