Re: Problem with DB_DataObject_FormBuilder and multiple links
| From: | Justin Patrin | Date: | Wed, 23 May 2007 18:35:44 +0000 |
| Subject: | Re: Problem with DB_DataObject_FormBuilder and multiple links | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-27362@lists.php.net to get a copy of this message | ||
On 5/23/07, Erik Lemcke <ELemcke@wwf.nl> wrote:
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 TABLEFormBuilder doesn't support hierselects internally (that's what you want is called). There's some code that someone wrote up to do that kind of thing in the docs here: http://pear.reversefold.com/dokuwiki/doku.php?id=pear:db_dataobject_formbuilder:beyond_advanced#creating_automatic_hierselects -- Justin Patrincat(cat_idtinyint(4) NOT NULL,cat_namevarchar(100) NOT NULL, PRIMARY KEY (cat_id) ) CREATE TABLEdoc(doc_idtinyint(4) NOT NULL auto_increment,doc_namevarchar(100) NOT NULL,sc_idtinyint(4) NOT NULL, PRIMARY KEY (doc_id) ) CREATE TABLEsubcat(sc_idtinyint(4) NOT NULL,sc_cat_idtinyint(4) NOT NULL,sc_namevarchar(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(); } ?>