I am trying to use the hierselect in a Quickform. I believe all values have been added to the form successfully, but i’m unable to retrieve the selected values.
Here is my code:
// Include QuickForm class
require_once 'HTML/QuickForm.php';
// Default URL: usually index.php
$target = 'index.php';
$form = new HTML_QuickForm('addForm', 'POST', $target);
// Add a header to the form
$form->addElement('header', 'MyHeader', 'Please Enter Details');
$form->addElement('text', 'productsname', 'Product Name');
$form->addRule('productsname', 'Enter Product Name', 'required', false, 'client');
$form->addElement('text', 'productsstyleno', 'Product Style No');
$form->addRule('productsstyleno', 'Enter Product Style No', 'required', false, 'client');
$form->addElement('text', 'productsprice', 'Product Price');
$form->addRule('productsprice', 'Price must be numeric', 'numeric', false, 'client');
$form->addRule('productsprice', 'Enter Product Price', 'required', false, 'client');
$form->addElement('text', 'productsfabric', 'Product Fabric');
$form->addElement('select', 'productscolour', 'Product Colour');
// create level 0 and level 1 arrays
// from database queries
try {
foreach ($db->query("SELECT category_id, category_name from tbl_categories WHERE category_parent = '43'") as $row) {
$id = $row['category_id'];
$name = $row['category_name'];
$categories[$id] = $name;
foreach ($db->query("SELECT category_id, category_name from tbl_categories WHERE category_parent = '$id'") as $row2) {
$cid = $row2['category_id'];
$cname = $row2['category_name'];
$subcategories[$id][$cid] = $cname;
}
}
unset($db);
} catch (PDOException $e) {
die ($e->getMessage());
}
// add hierselect element
$select = $form->addElement('hierselect', 'category', 'Category');
$select->setOptions(array($categories, $subcategories));
// Add a submit button
$form->addElement('submit', 'submit', ' Submit ');
I am using this to try and access the category Hierselect, but it just returns ‘Array’:
// print submitted values
// render and display the form
if ($form->validate()) {
$form->freeze();
echo 'You submitted the following data:';
$values = $form->getSubmitValues();
echo $values;
} else {
$form->display();
}
I’ve been tearing my hair out for 3 hours now, any help much appreciated.
Cheers,
Tim