Re: HTML Controls

From: Date: Mon, 26 Nov 2001 16:17:54 +0000
Subject: Re: HTML Controls
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-3113@lists.php.net to get a copy of this message
le 26/11/01 15:35, James Hurst à james@projects.new-media.co.uk a écrit : > Hi, > > I've just started writing a package to scratch a certain itch. That is, I > wanted to be able to create HTML controls in a more abstract way so that > programming against them because easy, ..almost 'VB' or 'Delphi' like. > I've > looked at HTML_QuickForm, but it doesn't really meet my requirements. I'll > explain why later. > > The api itself is loosely based on that of MS's .NET WebControls, which > inspired me in the first place. It is their clean api which made it very > attractive. > > The ultimate goal is to be able to create HTML controls, that: > > 1) Are easy to create. > 2) Maintain their own state. > 3) In the case of list controls, can be data-bound. > 4) Do not make 'designing' forms more difficult. > 5) Can optionally retain values over a session (for 'wizard' interfaces) > > Number 4 is of particular importance. I don't want the logic required by the > programmer's script to interfere with the page design, ..making reusability > and the inevitable (page redesign) more straight forward. > > A typical example of usage would be as follows: > > //*********************************************** > > <?php > > require_once "HTML_Controls/TextBox.php"; > require_once "HTML_Controls/Button.php"; > > // Setup the controls with their default properties. > // This should generally happen near the top of the script. > $txtName = new TextBox("txtName"); > $txtName->cssClass = "mytextclass"; > $txtName->maxLength = "20"; > > $btnSubmit = new Button("btnSubmit"); > ?> > > // Do your standard HTML stuff, then render the controls at the desired > point. > > <form name="blah" method="post"> > <p><b>Name:</b><br> > <?php $txtName->render(); ?> > </p> > > <?php $btnSubmit->render(); ?> > > ***********************************************// > > The really cool thing is having the controls maintain their state. Thus, > after you have created the controls at the top of the script, you can > interrogate them as part of your logic. If you want to use the value from > the textbox in a sql statement, you would use $txtName->text. > > Whilst I'm sure that many people find HTML_QuickForm very useful, you can > see how my goals might conflict. > > I'm focussing on absolute ease of use. Built in state maintenance (even > though it wouldn't suit _everyone_) is incredibly important to me. > > I guess what I'm asking is, should I code this to PEAR conventions and > submit it? If people are generally happy with the HTML_QuickForm method, or > think that my package might be too similar then I'll keep it separate. I > don't wish to tread on the toes of the HTML_QuickForm developers, but feel > that my code might offer a different perspective on the OO forms idea. > > Any thoughts? Hi James, This was our goal too. With Adam Daniel, we were thinking about such an API. I think this is doable within HTML_QuickForm but it will require some modifications. First, all form elements should go on the top level directory so that they will be then directly accessible as objects on their own. At the moment, HTML_QuickForm calls them separately when they are required. When the code calls $form->addElement('text','myText','value here','maxlength=20 class=myclass'), it does the same thing as if you were doing : $text = new HTML_QuickForm_text... These are also objects which have their own accessor methods. They can be called directly. Instead of calling render(), we call their toHtml() method. HTML_QuickForm class is just a sort of wrapper which handles their layout, their processing and their validation. We are currently working on a bridge to link it to ITX, PHPLIB templates and Smarty. The idea is to send a template to HTML_QuickForm which will then parse it with all its form elements. I would like also to go the other way round, by returning only raw data in an array of form elements. Instead of method toHtml() we would use toArray() for instance. The methods you are suggesting already exist for most of the elements. There is a getValue(), getType() and so on for each of them. The fact that they extend HTML_Common frees you to code more methods like getMaxLength() or getCSSClass() and their counterparts setMaxLength() and setCSSClass(). You would normally just need to call $text->getAttribute('maxlength') to access them. This make your coding more flexible and not as limited. I would suggest that you have a look at the Elements directory and tell us if this is what you are after. Of course, I understand that it would require a few modifications but they shouldn't be to complex. Regards, Bertrand Mansion Mamasam

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