Re: DB_DataObject_FormBuilder: how to override processForm() method
| From: | Giorgio Gorla | Date: | Thu, 11 Nov 2004 13:36:30 +0000 |
| Subject: | Re: DB_DataObject_FormBuilder: how to override processForm() method | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15438@lists.php.net to get a copy of this message | ||
Justin Patrin ha scritto:
On Wed, 10 Nov 2004 15:36:32 +0100, Giorgio Gorla <gmontag@tiscali.it> wrote:I need to insert a new record setting a natural primary key (not automatically generated).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.
<?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 {Since FB doesn't so this automatically, you would have to use: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);$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.
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.$form->freeze();} echo $form->toHtml(); ?> The code continues running processForm() from DB_DataObject_FormBuilder parent class instead the method written by my. Any suggestions?
Just make sure you've got overloading turned off for DataObject. Y, thanks.