Using HTML_Quickform_hierselect

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tencip

    Using HTML_Quickform_hierselect

    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:

    [snip]

    $sel =& $form->addElement('hi erselect', 'link_pid', 'Category and
    subcategory:');
    $sel->setMainOptions (getLinkCategor ies());
    $sel->setSecOptions( getLinkSubcateg ories());

    [/snip]

    AND>....

    [snip]
    function getLinkSubcateg ories()
    {
    require 'config.inc.php ';

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

    // 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($qu ery)
    or die("Query failed: " . mysql_error());

    $link_subcats = array(""=>"Sele ct a subcategory");

    while ($row = mysql_fetch_arr ay($result)) {
    $link_subcats[$row[pid]][$row[id]] = $row[name];
    }

    return $link_subcats;
    }

    [/snip]

    So, say we have:

    Main Category 1[color=blue]
    >SubCategory1 a
    >SubCategory1 b[/color]

    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.

    Thanks,
    Tencip
Working...