Re: DB_DataObject_FormBuilder: how to override processForm() method

From: Date: Thu, 11 Nov 2004 18:00:37 +0000
Subject: Re: DB_DataObject_FormBuilder: how to override processForm() method
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-15453@lists.php.net to get a copy of this message
On Thu, 11 Nov 2004 14:36:30 +0100, Giorgio Gorla <gmontag@tiscali.it> wrote: > Justin Patrin ha scritto: > > On Wed, 10 Nov 2004 15:36:32 +0100, Giorgio Gorla <gmontag@tiscali.it> wrote: > > > >>In order to insert a new record in a table with natural primary key, I > >>try overriding processForm() method, like suggested by documentation: > > > > Which docs were these? Could you point me to a specific place? I can't > > seem to find anything in the code which says FB supports this > > directly. > > > See in FormBuilder.php API doc the processForm() item. > I need to insert a new record setting a natural primary key (not > automatically generated). > Sorry, I'm still not seeing what you're referring to. The API docs don't say that you can put a processForm method in your DO....could you give me a link and the approximate location? > > > >><?php > >>// vim: set filetype=php ai ts=4 sw=4 et fdm=marker : > >> > >>require_once 'DB/DataObject/FormBuilder.php' ; > >> > >>class MyDBOF extends DB_DataObject_FormBuilder > >>{ > >> > >> function MyDBOF(&$do, $options = false) > >> { > >> $this->debug("<br>...run MyDBOF class by GG...<br>"); > >> parent::DB_DataObject_FormBuilder($do); > >> } > >> > >> function processForm($values) > >> { > >> $this->debug("<br>...run processForm() by > >> GG...<br>"); > >> ... my stuffs... > >> } > >>} > >> > >>$do = DB_DataObject::factory($_POST['object']); > >>$formBuilder = MyDBOF::create($do); > >>$form = $formBuilder->getForm(); > >>if ($form->validate()) { > >> $form->process(array(&$formBuilder, 'processForm'), false); > > > > > > Since FB doesn't so this automatically, you would have to use: > > $form->process(array(&$do, 'processForm'), false); > > > I see, but in this way I can't use FormBuilder functions to manage form > and pass data from form to DB obj. > > > > >> $form->freeze(); > >>} > >>echo $form->toHtml(); > >> > >>?> > >> > >>The code continues running processForm() from DB_DataObject_FormBuilder > >>parent class instead the method written by my. > >> > >>Any suggestions? > >> > > > > > > However, if all you're doing is setting a key, you should really just > > be using preProcessForm(). > > > > function preProcessForm(&$values) { > > $values['key'] = new key value; > > } > > > It's not my problem. Then what is your problem? What do you mean by a "natural primary key"? Shouldn't this just be one of your fields? If you're setting a special value for a key algorithmically, then you can do it in preProcessForm(). Tell me what your code needs to do (or show me your processForm that you wrote before) and I'll tell you how to do it. > > > Just make sure you've got overloading turned off for DataObject. > > > Y, thanks. > -- Justin Patrin

« previous php.pear.general (#15453) next »