Re: Re: Your opinion about QuickForm2 API

From: Date: Mon, 16 Apr 2007 21:40:16 +0000
Subject: Re: Re: Your opinion about QuickForm2 API
References: 1 2 3  Groups: php.pear.dev php.pear.general 
Request: Send a blank email to pear-dev+get-46262@lists.php.net to get a copy of this message
On 4/16/07, Alexey Borzov <borz_off@cs.msu.su> wrote:
Hi, Gregory Beaver wrote: I've honestly found the addElement() API to be difficult to work with in the past, so simplifying it would be a welcome change. However, I don't think "addElement" needs to exist in Quickform2. Have you considered an API similar to the following? <?php $form = new HTML_Quickform2; $form['action'] = '/path/to/action.php'; $form['method'] = 'post'; // or $form['attrs'] = array('action' => '/path/to/action.php', 'method' => 'post'); $g = $form->group['mygroup']; $g->text = array('name' => 'aText', 'size' => 50, 'default' => 'whatever'); $g->select = array('name' => 'aSelect', 'options' => array(...)); // or $g->text(array('name' => 'aText', 'size' => 50))
          ->validate['regex'] =  '/\w+/';
$g->select(array('name' => 'aSelect', 'options' => array()) $select = $g->select['aSelect']; // or $form->select['aSelect']; $select->options['another'] = 1; $select->validate['custom'] = 'is_numeric'; ?> With all due respect, SimpleXML API which you seem to use as inspiration here uses addAttribute() and addChild() methods for adding attributes and child nodes, it doesn't work as shown above. ;) We considered something like that, but decided to go with DOM-like API for now.
While DOM is powerful it is also incredibly verbose. I use it in JS sometimes but I also revert to innerHTML half the time just to get things done. Of course, using something like SimpleXML is also limiting. Building the core on DOM sounds great to me for flexibility. I think that it would also be great to have a simplified API such as above. That *should* be doable with an add-on package, though, I'd think.
BTW, while you are here, Bertrand is having some problems generating docs for QF2: http://quickform.mamasam.com/docs/ The generation process seems to finish in the middle of writing files with no errors in the log. Try clicking the links and observe a bunch of 404s.
-- Justin Patrin

« previous php.pear.dev (#46262) next »