Re: DB_DataObject_FormBuilder: how to override processForm() method
| From: | Justin Patrin | Date: | Wed, 10 Nov 2004 17:47:06 +0000 |
| Subject: | Re: DB_DataObject_FormBuilder: how to override processForm() method | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15422@lists.php.net to get a copy of this message | ||
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.
>
> <?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);
> $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;
}
Just make sure you've got overloading turned off for DataObject.
--
paperCrane --Justin Patrin--