Quickform suggestion

From: Date: Mon, 21 Apr 2003 22:34:42 +0000
Subject: Quickform suggestion
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-15291@lists.php.net to get a copy of this message
Hi there, I´ve spent some time today trying out the new Quickform 3 package, so far I´m very impressed - great work, guys ;-) So far, I´ve always used HTML_OOH_Form for nearly all my applications and have always liked the elegance with which you can quickly define quite complex forms. That´s where I still have some kind of a problem with Quickform... well, not really a problem, but I don´t like how my code looks when I define a form with it. Right now, I can define new form elements in three ways: // Way 1: Use some loose arguments... $form->addElement('type', 'name', 'label'); // Way 2: Make a new element object... $obj = &new HTML_Quickform_text('name', 'label'); $form->addElement($obj); // Way 3: Use a factory method to create an element object... $obj = &HTML_QuickForm::createElement('type', 'name', 'label'); $form->addElement($obj); Well, choice is good, they say. But I´d like to have some consistency in my code - and also, I can´t really influence *all* aspects of one form field with just one function call. If I want to make use of validation rules, filters, groups etc., I have to touch each affected field again and again... a good example is in the first Quickform example script: $form->addElement('select', 'iselTest', 'Test Select:', array('A'=>'A', 'B'=>'B','C'=>'C','D'=>'D')); $select = &$form->getElement('iselTest'); $select->setSize(5); $select->setMultiple(true); Here, one has to first define an element with addElement(), but there´s no possibility to define things like the size, multiselect or other options right away. To do that, one has to retrieve the freshly created element from the form object, and make some additional manipulations - why not add some more parameters on object creation? Same goes for validation rules... I have to call addRule() on each field again which I want to have validated... okay, it works, and it´s logical as well, but does it look nice? I think it can really clutter your code when dealing with complex forms. In OOH_Form, I can define all those things in one go:
$form->addElement(array('type'      => 'text',
                        'name'      => 'elName',
                        'size'      => 40,
                        'label'     => 'Label:',
                        'value'     => 'some value',
                        'minlength' => 2,
                        'length_e'  => 'Enter at least 2 chars',
                        'accesskey' => 'e'
                        )
                  );
Because an associative array is being used, I can pass as many options as I want, and because they´re all named I also know which option means what at any time, even when I change the order of arguments. This could even be extended to passing filter or group names to the array, to match all of Quickform´s functionality. IMHO, such a form of element definition adds lots of readability to the code, and will also make understanding of Quickform for newbies easier. Then again, maybe it´s just me and nobody agrees with me anyway - and maybe I´ve just been using OOH for too long :-) Besides this little optical issue, Quickform is truly a great package. Regards, Markus

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