Re: DB_DataObject_FormBuilder: how to override processForm() method

From: 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:
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).
<?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.
Just make sure you've got overloading turned off for DataObject. Y, thanks.


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