Problem with DB_DataObject_FormBuilder and multiple links
| From: | Erik Lemcke | Date: | Wed, 23 May 2007 12:28:38 +0000 |
| Subject: | Problem with DB_DataObject_FormBuilder and multiple links | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-27359@lists.php.net to get a copy of this message | ||
I've ran into a problem while creating a form for a system I'm building.
The system is supposed to be used for storing documents, below is a simplified SQL dump of the table
structure
CREATE TABLE
cat (
cat_id tinyint(4) NOT NULL,
cat_name varchar(100) NOT NULL,
PRIMARY KEY (cat_id)
)
CREATE TABLE doc (
doc_id tinyint(4) NOT NULL auto_increment,
doc_name varchar(100) NOT NULL,
sc_id tinyint(4) NOT NULL,
PRIMARY KEY ( doc_id)
)
CREATE TABLE subcat (
sc_id tinyint(4) NOT NULL,
sc_cat_id tinyint(4) NOT NULL,
sc_name varchar(100) NOT NULL,
PRIMARY KEY (sc_id)
)
A category can contain 0 or more subcategories
A subcategory can contain 0 or more documents.
So with that information I created my links file:
[doc]
sc_id = subcat:sc_id
[subcat]
sc_cat_id = cat:cat_id
That's all quite straight forward I think.
Now the difficulty I have is getting this into a form. What I actually want is that users can choose
a category (with a select box)
Based upon their category selection they should be able to select a subcategory, but the select box
should only display subcategories that belong to the selected category.
Is there any way to do this with DB_DataObject_FormBuilder?
p.s. this is the code I use to create the form:
<?
require_once 'DB/DataObject.php';
require_once 'DB.php';
require_once 'DB/DataObject/FormBuilder.php';
$config = parse_ini_file( "config.ini", true);
$db =& DB::connect($config["DB_DataObject"]["database"]);
foreach($config as $class=>$values) {
$options = &PEAR::getStaticProperty($class,'options');
$options = $values;
}
$doc = DB_DataObject::factory('doc');
$fg = DB_DataObject_FormBuilder::create($doc);
$form = $fg->getForm();
if ($form->validate()) {
$form->process(array(&$fg,'processForm'), false);
} else {
echo $form->toHtml();
}
?>
This message has been scanned for malware by SurfControl plc. www.surfcontrol.com