compared with
Current by Darby Felton
on Sep 04, 2007 07:28.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (112)

View Page History
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
{zone-data:revision}
1.0 - 28 August 2007: Initial Proposal
1.1 - 4 September 2007: Changed use cases, modified requirements
{zone-data}


{zone-data:requirements}
Most requirements take the form of "foo will do ...." or "foo will not support ...", although different words and sentence structure might be used. Adding functionality to your proposal is requirements creep (bad), unless listed below. Discuss major changes with your team first, and then open a "feature improvement" issue against this component.

* This component *will* validate form input.
* This component *will* filter form input.
* This component *will* support Zend_Filter filters.
* This component *will* support Zend_Validate validations.
* This component *will* support custom filters and validations.
* This component *will* allow forms to span multiple pages.
* This component *will* manage temporary data storage of multiple pages through storage containers (Zend_Session).
{deck:id=Usecases}
{card:label=Single-Page Form}
A basic single-page form consisting of two fields with validations and filters for each. Because the filters and validators for the password field would be the same as the username field, I use the getFlow() method call on the field instance to copy the flow over to the password, saving lines. This is just one example of the usefulness of a "flow." Also, added fields can be accessed like properties of the Zend_Form object, as username is done in this example.
{code}
$form = new Zend_Form();
->addValidator('StringLength', array(3,12));
$form->addField('password')
->addFlow($form->getField('username')->getFlow()); ->addFlow($form->username->getFlow());
$form->setDataSource($_POST);


$form->addField('password_confirmation')
->addFlow($form->getField('password')->getFlow()) ->addFlow($form->password->getFlow())
// The following flow only runs if the "password" field is valid!
->addConditional('valid', 'password')
{card}
{card:label=Multi-Page Form}
This use case shows how to create a multi-page form, and how to handle view rendering for it. It also shows that pages may be accessed like properties of a Zend_Form object, just like fields.
{code}
$form = new Zend_Form();
->addValidator('StringLength', array(5,12))
->addFilter('trim');
$page_two = $form->addPage('optional_info');
$page_two->addField('first_name') $form->addPage('optional_info');
$form->page_two->addField('first_name')
->addFilter('strtoupper');

{
// Render the page
$this->render('pages/' . $form->getCurrentPageName() $form->getCurrentPageId() . '.phtml');
}
else
$page->addField('username')
->addValidator('Alnum', array('message' => '%s must be alphanumeric!'))
->addValuidator('StringLength', array(2, 5, 'message' => array(
Zend_Validate_StringLength::TOO_SHORT => '%s is too short!',
Zend_Validate_StringLength::TOO_LONG => '%s is too long!'
}

$this->render('pages/' . $form->getCurrentPageName()); $form->getCurrentPageId());
{code}
{card}

{zone-data:skeletons}
There are more skeletons below this deck also.
These are just the skeletons of the main classes. For complete class information, download the package or browse the subversion repository at: http://sourceforge.net/projects/zendform
{composition-setup}
{deck:id=Skeletons}
* @var Zend_Form_Flow_Page|Zend_Form_Element_Page
*/
public protected $_pages = null;

/**

/**
* Options for error messages
*/
const ERROR_AGGREGATE = 1;
const ERROR_BY_FIELD = 2;

/**
* Add a page to the page flow. Throws an exception if
* the ID is already taken, the parent does not exist, or
* @param string|Zend_Form_Page $parent OPTIONAL Parent page, the added page
* will go after this.
* @param int $relation OPTIONAL Where to place it in relation to parent (above or below)
* @return Zend_Form_Page
* @throws Zend_Form_Exception

/**
* Branch the page flow.
*
* @param string $id A unique identifier for the branch.
* @param string|Zend_Form_Flow_Conditional $conditional The conditional for the branch.
* @param array|string $options OPTIONAL The options for the conditional.
* @param string|Zend_Form_Page $parent OPTIONAL Parent page, the added page
* will go after this.
* @return Zend_Form_Page
* @throws Zend_Form_Exception
*/
public function addBranch($id, $conditional, $options = null, $parent = null, $relation = null)
{}

/**
* Add a field to the form. This is used for single-page forms.
* Will throw an exception if multi-page forms are setup.
* @param string $id A unique identifier for the field.
* @param string $parent OPTIONAL Parent field.
* @param int $relation OPTIONAL Where to place it in relation to parent (above or below)
* @return Zend_Form_Element_Field
* @throws Zend_Form_Exception

/**
* Gets the page specified by $id
* Gets a page by it's ID. This method is only available for
* multi-page forms.
*
* @param string $id The unique ID of the page.
* @param string $id The id of the field.
* @return Zend_Form_Element_Page
* @throws Zend_Form_Exception
* @throws Zend_Form_Exception
*/
public function &getPage($id)

/**
* Gets the field specified by $id
* Gets a field by it's ID. This method is only available for
* single page forms.
*
* @param string $id The unique ID of the field.
* @param string $id The id of the field.
* @return Zend_Form_Element_Field
* @throws Zend_Form_Exception
* @throws Zend_Form_Exception
*/
public function &getField($id)
* @param string|Zend_Form_Storage $container A string containing the
* class name or an instance itself.
* @param array|string $options OPTIONAL The options for the container if initializing a new one.
* @return Zend_Form
* @throws Zend_Form_Exception

/**
* Get the temporary persistent storage container. If no container is set,
* an exception will be raised. The storage container is returned by reference.
*
* @return Zend_Form_Storage

/**
* Gets the current page in a multi-page form.
* Get the page object of the current page. If no current page
* is set (first visit on a page), then the session will be set.
*
* Storage container must be set before using this method!
*
* @return Zend_Form_Element_Page
* @throws Zend_Form_Exception
*/
public function &getCurrentPage()

/**
* Gets the current page ID in a multi-page form.
* Should probably be getCurrentPageId()
* Attempts to progress to the next page of the multi-page form.
* If there is a next page, method returns true, otherwise
* false is returned, signaling the end of a multi-page form.
*
* Ignore the parameters, they are for internal use.
*
* @param array &$chain Ignore.
* @param array $tree Ignore.
* @return string boolean
* @throws Zend_Form_Exception
*/
public function getCurrentPageName()
public function nextPage(&$chain = null, $tree = null)
{}

/**
* Gets the current page Id.
*
* Storage container must be set before calling this method!
*
* @return string
*/
public function getCurrentPageId()
{}

/**
* Returns whether the data is valid. Runs validations if
* they haven't ran already. You can use the optional

/**
* Checks if data is valid and ready to go to next page
* if there is one. If so, it sets the next page in the storage container
* and returns true, otherwise it returns false, signaling the end
* of a multipage form.
* Reset the current page to the first page and clear any stored data.
*
* Storage container must be set before calling this method!
*
* @return boolean
* @throws Zend_Form_Exception
*/
public function nextPage() resetPage()
{}

/**
* Set the data source for validation
* Set the data source for validation. The data source must be an array
* with keys being field ids.
*
* @param array $source Source of data for validation.

/**
* Retrieve error messages. Normally they are organized by
* field ID. If $strip_keys is true, they are flattened to
* a single array.
* Get the error messages for the current page. There are two options
* for the style:
* ERROR_BY_FIELD - Organize error messages with keys being field Ids.
* ERROR_AGGREGATE - Do not organize by field Id, just list error messages.
*
* @param boolean $strip_keys OPTIONAL Whether or not to flatten array.
* @param integer $style The style of error messages.
* @return array
* @throws Zend_Form_Exception
*/
public function getMessages($strip_keys = false)
public function getMessages($style = self::ERROR_BY_FIELD)
{}

/**
* Checks if a field has errors. If $field is not given,
* the entire form is checked.
* Check if a field has any errors. If no field parameter is given,
* it checks if any field has errors.
*
* @param boolean $field OPTIONAL The field ID.
* @param string $field OPTIONAL Field Id to check for errors.
* @return array boolean
* @throws Zend_Form_Exception
*/
public function hasErrors($field = null)
public function __call($method, $arguements)
{}

/**
* Magic method __get() to access field/page Ids via properties.
*
* @throws Zend_Form_Exception
*/
public function &__get($id)
{}
}
{code}

/**
* Create a Zend_Form_Element object instance. The ID must
* follow the same naming standards as a PHP variable.
*
* @param string $id The unique ID of the element.

/**
* Get the unique ID of the element.
*
* @return string
public function getId()
{}

/**
* Internal method used to dynamically load a given class. The optional
* parameters are used to check whether the class is part of an interface and
* also to pass options to the constructor.
*
* @param string $name The name of the class, following Zend standards.
* @param string $interface OPTIONAL An interface that the class must inherit from.
* @param array $options OPTIONAL An array of parameters for the constructor.
* @return Zend_Validate_Interface|Zend_Filter_Interface
* @throws Zend_Form_Element_Exception
*/
protected function _getClass($name, $interface = null, $options = null)
{}
}
{code}
* the end of the flow.
* @param int $relation Where to put this item in relation to $position.
* @return Zend_Form_Element_Field Zend_Form_Page
* @throws Zend_Form_Element_Exception
*/
public function addValidator($item, $options = null, $position = null, $relation = Zend_Form_Flow::INSERT_AFTER)
*
* @param mixed $item The filter to add to the flow.
* @param array $options OPTIONAL Options to pass to the class.
* @param string|mixed $position OPTIONAL Where to put this new item, if not at
* the end of the flow.
* @param int $relation Where to put this item in relation to $position.
* @return Zend_Form_Element_Field Zend_Form_Page
* @throws Zend_Form_Element_Exception
*/
public function addFilter($item, $options = null, $position = null, $relation = Zend_Form_Flow::INSERT_AFTER)
*
* @param mixed $item The conditional to add to the flow.
* @param array $options OPTIONAL Options to pass to the class.
* @param string|mixed $position OPTIONAL Where to put this new item, if not at
* the end of the flow.
* @param int $relation Where to put this item in relation to $position.
* @return Zend_Form_Element_Field Zend_Form_Page
* @throws Zend_Form_Element_Exception
*/
public function addConditional($item, $options = null, $position = null, $relation = Zend_Form_Flow::INSERT_AFTER)
{}

/**
* Add a complete flow to the field. The flow can be retrieved from other
* fields using getFlow().
*
* @param Zend_Form_Flow $flow The flow to append.
* @return Zend_Form_Element_Field
* @throws Zend_Form_Element_Exception
*/
public function addFlow($flow)

/**
* Gets the field's flow.
* Gets the complete flow from the field.
*
* @return Zend_Form_Flow
* @throws Zend_Form_Element_Exception
*/
public function getFlow()

/**
* Run the field flow.
* Run the validations and filters of the field.
*
* @param string $value The value of the field.
* @param array &$errors Reference to error message holding array.
* @param array &$errors A reference to an array to populate with error messages.
* @param Zend_Form &$form A reference to the form instance. calling Zend_Form object.
* @return Zend_Form_Element_Field string
* @throws Zend_Form_Element_Exception
*/
public function run($value, &$errors, &$form)

/**
* Formats the an error message, replacing %s with the field name. field's
* name.
*
* @param string &$message The message.
* @return Zend_Form_Element_Field
* @throws Zend_Form_Element_Exception
* @param string &$message A reference to the string which needs formatting.
*/
private function _formatErrorMessage(&$message)

/**
* Gets the index of an element in the flow by ID.
* Gets the numerical array index of an item in the flow.
*
* @param string $name The ID name of the element. class.
* @return integer
* @throws Zend_Form_Element_Exception
*/
private function _indexOfValidatorOrFilter($name)

/**
* Magic method used for dynamic methods.
*/
public function __call($method, $arguements)
{zone-data}

{zone-template-instance}
{zone-template-instance}]]></ac:plain-text-body></ac:macro>