For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > May 2007 > Problem with DB_DataObject_FormBuilder and multiple links









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problem with DB_DataObject_FormBuilder and multiple links
Erik Lemcke

2007-05-23, 7:03 pm

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 wantis 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

Adsterderup70

2007-05-29, 12:52 am

A teen boy fukcs his black-skinned neighbour
http://www.cross-nation-couples.org/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com