Ticket #159 (new defect)

Opened 4 months ago

Solar_Form_Element

Reported by: rodrigo moraes <rodrigo.moraes@…> Owned by: pmjones
Priority: security Component: code
Keywords: Cc:

Description

Here is a implementation of Solar_Form_Element and related changes in Solar_Form for your review and consideration:

http://code.google.com/p/tipos/source/browse/branches/Solar_Form/Solar/Form/Element.php http://code.google.com/p/tipos/source/browse/branches/Solar_Form/Solar/Form.php

Solar_Form_Element enforces default keys and casts its data, freeing other classes from doing these tasks (Solar_Form, Solar_View_Helper_Form, Solar_View_Helper_FormElement).

As far as I can tell, most common uses should remain compatible with current Solar_Form. A few adaptations are required in Solar_View_Helper_Form.

A notable issue inherited from Solar_Struct is that new keys can't be added directly to array properties of the element. For example, $element['attribs']:

<?php
// This won't work: 'foo' is not added to the 'attribs' array.
$element['attribs']['foo'] = 'bar';

// Getting and resetting 'attribs' is the ugly workaround.
$attribs = $element['attribs'];
$attribs['foo'] = 'bar';
$element['attribs'] = $attribs;

// Using a method is a shorter workaround.
$element->addAttribs('foo', 'bar');
?>

I'd suggest to remove or mark as deprecated some methods related directly to a single element in Solar_Form, and use the respective element methods instead. They are:

  • setAttribs()
  • setType()
  • addFilter()
  • addInvalid()

getValue() and setValue() are exceptions because public use is more common and they are nice shortcuts. The others can be called via $form->getElement($name)->setAttribs($data) etc.

Attachments

Add/Change #159 (Solar_Form_Element)

Author



Action
as new
 
Note: See TracTickets for help on using tickets.