Re: Quickform suggestion

From: Date: Tue, 22 Apr 2003 06:26:36 +0000
Subject: Re: Quickform suggestion
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-15306@lists.php.net to get a copy of this message
Markus Wolff wrote:
Hi there, I´ve spent some time today trying out the new Quickform 3 package, so far I´m very impressed - great work, guys ;-)
Thanks. ;
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);
You don't *have* to use all three ways of creating elements in your scripts, do you? ; The preferred way is of course 'Way 1', I don't know why 'Way 2' is even described in examples, 'Way 3' is mostly used while creating groups, where you have to first create all group's elements and then add the group containing them to the form.
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?
In fact there *are* more parameters on object creation. ;] This example can look like this: $form->addElement('select', 'iselTest', 'Test Select:', array('A'=>'A', 'B'=>'B', 'C'=>'C', 'D'=>'D'), array('size'=>5, 'multiple'=>'multiple'));
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.
As for rules and filters, this is the architecture question: they are kept/applied in form object, not in element objects. Besides I consider it more readable when you first define all form elements and then define actions to apply to them. ;

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