470,833 Members | 1,407 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

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('hierselect', 'link_pid', 'Category and
subcategory:');
$sel->setMainOptions(getLinkCategories());
$sel->setSecOptions(getLinkSubcategories());

[/snip]

AND>....

[snip]
function getLinkSubcategories()
{
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($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;
}

[/snip]

So, say we have:

Main Category 1
SubCategory1a
SubCategory1b


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
Jul 17 '05 #1
0 1251

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by rawCoder | last post: by
10 posts views Thread by Christopher Benson-Manica | last post: by
17 posts views Thread by beliavsky | last post: by
14 posts views Thread by john.burton.email | last post: by
5 posts views Thread by Enos Meroka | last post: by
12 posts views Thread by Calum Grant | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.