Create hidden zf form element and add validator for unsigned float field

Create hidden zf form element
Default hidden element created by zend_form are often come up with its (probably unwelcoming) decorators, eg. its wrappers outside. Those wrappers could break the layout by adding in unnecessary blank lines.
To avoid this, just use the function addDecorators to add a displayNone class name to the element's wrappers:

$id = $this -> createElement("hidden","id");
$id -> setLabel("Hidden ID") -> addDecorators(
array('ViewHelper'
,array('HtmlTag',array('tag'=>'dt','class'=>'displayNone'))
,array('label',array('tag'=>'dd','class'=>'displayNone'))
)
);

The css code for displayNone class is:

.displayNone
{
display:none;
}

Add validator for unsigned float field
It's easy if you know the Zend_Validate_GreaterThan validator exists:

$quantity = $this->createElement('text','quantity');
$quantity ->setLabel('Quantity:')
->addValidator('float')
->addValidator(new Zend_Validate_GreaterThan(array('min' => 0)) )
->setRequired(true)
->addValidator('NotEmpty', true);

English

Add new comment